国内主流的pypi源:
- 豆瓣
- 阿里云
- 清华
- 中科大
- (官方 )
考虑到翻墙后,国内的源比较慢,故加上官方源 : https://pypi.org/simple
[global]
index-url = https://pypi.doubanio.com/simple
extra-index-url = https://mirrors.aliyun.com/pypi/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
https://mirrors.ustc.edu.cn/pypi/web/simple/
https://pypi.org/simple/
[install]
trusted-host = pypi.doubanio.com
mirrors.aliyun.com
pypi.tuna.tsinghua.edu.cn
mirrors.ustc.edu.cn
pypi.org
disable-pip-version-check = true
timeout = 6000
注: 不要重复写成
extra-index-url=...
extra-index-url=...
trusted-host = ...
trusted-host = ...
会报错(DuplicationError
), 所以还是写成上述方式吧。
虚拟环境中的 pip.conf 配置
对新建的项目,往往会在其root目录建立虚拟环境,此时pip如果想更改配置,需在
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
比如用pipenv建立虚拟环境,如果想改某项目下的 pip 配置,则首先在对应的项目目录下启动虚拟环境pipenv shell
, 然后用 which pip
查看路径,如:
/home/XX/.local/share/virtualenvs/project-6CoWjSse/bin/pip
然后在对应的 /project-6CoWjSse/
下建立 一个 pip.conf
,然后根据需求更改配置即可。
pipenv 的 源修改
default
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"改为豆瓣源
[[source]]
url = "https://pypi.doubanio.com/simple/"
verify_ssl = true
name = "pypi.doubanio.com"