使用國內鏡像源來加速python pypi包的安裝

來源:互聯網
上載者:User

標籤:

pipy國內鏡像目前有:

 

http://pypi.douban.com/  豆瓣

http://pypi.hustunique.com/  華中理工大學

http://pypi.sdutlinux.org/  山東理工大學

http://pypi.mirrors.ustc.edu.cn/  中國科學技術大學

 

對於pip這種線上安裝的方式來說,很方便,但網路不穩定的話很要命。使用國內鏡像相對好一些,

 

如果想手動指定源,可以在pip後面跟-i 來指定源,比如用豆瓣的源來安裝web.py架構:

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

 

注意後面要有/simple目錄!!!

 

要配製成預設的話,需要建立或修改設定檔(linux的檔案在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),修改內容為:

code:

[global]

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

 

這樣在使用pip來安裝時,會預設調用該鏡像。

更多配置參數見:http://www.pip-installer.org/en/latest/configuration.html

 

 

 

ConfigurationConfig file

pip allows you to set all command line option defaults in a standard ini style config file.

The names and locations of the configuration files vary slightly across platforms.

  • On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf
  • On Windows, the configuration file is: %HOME%\pip\pip.ini

You can set a custom path location for the config file using the environment variable PIP_CONFIG_FILE.

The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (--index-url) and set the HTTP timeout (--default-timeout) to 60 seconds your config file would look like this:

[global]timeout = 60index-url = http://download.zope.org/ppix

Each subcommand can be configured optionally in its own section so that every global setting with the same name will be overridden; e.g. decreasing the timeout to 10 seconds when running the freeze(Freezing Requirements) command and using 60 seconds for all other commands is possible with:

[global]timeout = 60[freeze]timeout = 10

Boolean options like --ignore-installed or --no-dependencies can be set like this:

[install]ignore-installed = trueno-dependencies = yes

Appending options like --find-links can be written on multiple lines:

[global]find-links =    http://download.example.com[install]find-links =    http://mirror1.example.com    http://mirror2.example.com
Environment Variables

pip’s command line options can be set with environment variables using the formatPIP_<UPPER_LONG_NAME> . Dashes (-) have to replaced with underscores (_).

For example, to set the default timeout:

export PIP_DEFAULT_TIMEOUT=60

This is the same as passing the option to pip directly:

pip --default-timeout=60 [...]

To set options that can be set multiple times on the command line, just add spaces in between values. For example:

export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"

is the same as calling:

pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com
Config Precedence

Command line options have precedence over environment variables, which have precedence over the config file.

Within the config file, command specific sections have precedence over the global section.

Examples:

  • --host=foo overrides PIP_HOST=foo
  • PIP_HOST=foo overrides a config file with [global] host = foo
  • A command specific section in the config file [<command>] host = bar overrides the option with same name in the [global] config file section
Command Completion

pip comes with support for command line completion in bash and zsh.

To setup for bash:

$ pip completion --bash >> ~/.profile

To setup for zsh:

$ pip completion --zsh >> ~/.zprofile

Alternatively, you can use the result of the completion command directly with the eval function of you shell, e.g. by adding the following to your startup file:

eval "`pip completion --bash`"
Next  Previous


Window 需要修改:

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

Java代碼  
  1. index_url = OptionMaker(  
  2.     ‘-i‘, ‘--index-url‘, ‘--pypi-url‘,  
  3.     dest=‘index_url‘,  
  4.     metavar=‘URL‘,  
  5.     #default=‘https://pypi.python.org/simple/‘,  
  6.      default=‘http://mirrors.bistu.edu.cn/pypi/‘,  
  7.     help=‘Base URL of Python Package Index (default %default).‘)  

 

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

 

Java代碼  
  1. class SearchCommand(Command):  
  2.     """Search for PyPI packages whose name or summary contains <query>."""  
  3.     name = ‘search‘  
  4.     usage = """  
  5.       %prog [options] <query>"""  
  6.     summary = ‘Search PyPI for packages.‘  
  7.   
  8.     def __init__(self, *args, **kw):  
  9.         super(SearchCommand, self).__init__(*args, **kw)  
  10.         self.cmd_opts.add_option(  
  11.             ‘--index‘,  
  12.             dest=‘index‘,  
  13.             metavar=‘URL‘,  
  14.             #default=‘https://pypi.python.org/pypi‘,  
  15.             default=‘http://mirrors.bistu.edu.cn/pypi/‘,  
  16.             help=‘Base URL of Python Package Index (default %default)‘)  
  17.   
  18.         self.parser.insert_option_group(0, self.cmd_opts)  

 

[Linux]修改easy_install和pip的鏡像地址

使用easy_install和pip會讓Pyhthon的模組安裝和管理變得非常簡單,但是,如果你身在國內的話,從官方的鏡像下載的速度是很令人抓狂的事情,如同修改apt-get或yum的鏡像地址一樣,easy_install和pip也需要修改鏡像地址。修改easy_install和pip的鏡像地址通常可以有以下兩種方法,可以分別使用命令和配置方式實現。

方法1:命令方式臨時修改
easy_install:

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

pip:

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

 

方法2:配置方式修改
easy_install:
1.開啟pydistutils.cfg

1
vi ~/.pydistutils.cfg

2.寫入以下內容

12
[easy_install]index_url = http://e.pypi.python.org/simple

pip:
1.開啟pip.conf

1
vi ~/.pip/pip.conf

2.寫入以下內容

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

速度比較快的國內鏡像,都來自清華大學,伺服器在北京。公網的伺服器為官方鏡像
公網:http://e.pypi.python.org/simple
教育網:http://pypi.tuna.tsinghua.edu.cn/simple

使用國內鏡像源來加速python pypi包的安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.