由于pip 默认使用Python的官方源pypi.python.org/pypi,导致我们经常使用pip装包时速度过慢或者无法安装(请求超时)等问题,所以国内用户建议使用pip比较合适的源。
常用的pip源
豆瓣:http://pypi.douban.com/simple/ 清华:http://pypi.tuna.tsinghua.edu.cn/simple/ 阿里云: https://mirrors.aliyun.com/pypi/simple/ 华为云源:https://mirrors.huaweicloud.com/repository/pypi/simple/
安装pip
如果没有安装pip包,可以官网下载get-pip.py文件,然后执行安装命令: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py -i http://pypi.douban.com --trusted-host pypi.douban.com
使用1:pip下载时指定源
pip install tornado -i http://pypi.douban.com/simple/ trusted-host = http://pypi.douban.com pip install -r req.txt -i http://pypi.douban.com/simple/
-i :指定pip源 trusted-host :说明可信的pip源
使用2: 创建配置文件,定义pip安装源
Windows设置
C:\Users\Admin\pip\pip.ini
Linux设置
$HOME/.config/pip/pip.conf 或者 $HOME/.pip/pip.conf
内容
[global] timeout =6000 index-url =http://pypi.douban.com/simple/ [install] use-mirrors =true mirrors =http://pypi.douban.com/simple/ trusted-host =pypi.douban.com
简写:
[global] index-url =http://pypi.douban.com/simple/ [install] trusted-host =pypi.douban.com
其他
使用setup.py安装依赖库, 还是会从默认的http://pypi.python.org下载
~/.pydistutils.cfg 文件,内容如下:
[easy_install] timeout = 60 index_url = https://pypi.douban.com/simple