使用国内镜像源来加速python pypi包的安装

pipy国内镜像目前有:

要配制成默认的话,需要创建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),修改内容为:

[global]
index-url = http://pypi.douban.com/simple

如果想手动指定源,可以在pip后面跟-i 来指定源,比如用豆瓣的源来安装web.py框架:

pip install web.py -i http://pypi.douban.com/simple

注意后面要有/simple目录。

Windows

修改%PYTHON_HOME%\Lib\site-packages\pip\cmdoptions.py

    index_url = OptionMaker(  
'-i', '--index-url', '--pypi-url',
dest='index_url',
metavar='URL',
#default='https://pypi.python.org/simple/',
default='http://mirrors.bistu.edu.cn/pypi/',
help='Base URL of Python Package Index (default %default).')

%PYTHON_HOME%\Lib\site-packages\pip\commands\search.py

    class SearchCommand(Command):  
"""Search for PyPI packages whose name or summary contains <query>."""
name = 'search'
usage = """
%prog [options] <query>"""
summary = 'Search PyPI for packages.'

def __init__(self, *args, **kw):
super(SearchCommand, self).__init__(*args, **kw)
self.cmd_opts.add_option(
'--index',
dest='index',
metavar='URL',
#default='https://pypi.python.org/pypi',
default='http://mirrors.bistu.edu.cn/pypi/',
help='Base URL of Python Package Index (default %default)')

self.parser.insert_option_group(0, self.cmd_opts)

Linux

1.命令方式临时修改

easy_install -i http://e.pypi.python.org/simple fabric
pip -i http://e.pypi.python.org/simple install fabric

2.配置方式修改

vi ~/.pydistutils.cfg

[easy_install]
index_url = http://e.pypi.python.org/simple
vi ~/.pip/pip.conf

[global]
index-url = http://e.pypi.python.org/simple