国内常见的 pip 源
来源 | 链接 |
---|---|
阿里云 | http://mirrors.aliyun.com/pypi/simple/ |
中国科技大学 | https://pypi.mirrors.ustc.edu.cn/simple/ |
豆瓣 | http://pypi.douban.com/simple/ |
清华大学 | https://pypi.tuna.tsinghua.edu.cn/simple/ |
临时使用方法
-i 加 url,举例:
pip install selenium -i http://pypi.douban.com/simple
如果使用的是 http 的源,会报如下错误:
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
此时需要信任主机,使用 --trusted-host
:
pip install selenium -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
如果有报错:
ERROR: Cannot unpack file C:\Users\issusers\AppData\Local\Temp\pip-unpack-6x9ra6uh\simple.html (downloaded from C:\Users\issusers\AppData\Local\Temp\pip-req-build-zoljdd4t, content-type: text/html); cannot detect archive format
ERROR: Cannot determine archive format of C:\Users\issusers\AppData\Local\Temp\pip-req-build-zoljdd4t
说明该源下可能没有同步到你需要的包,可以尝试更换源进行下载。
永久设置 pip 源
通过编辑配置文件
在当前用户根目录下,创建 .pip
目录,编辑配置文件
mkdir ~/.pip
tee ~/.pip/pip.conf <<-'EOF'
[global]
timeout=600
index-url=https://mirrors.aliyun.com/pypi/simple/
EOF
命令行配置 pip 源
如果你不想编写配置文件,可以使用一条命令配置 pip 源,会自动生成以上目录及文件
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
# 升级 pip
pip install -i https://mirrors.aliyun.com/pypi/simple/ pip -U
# 生成 pip 配置文件
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/