用pip下载一些软件包,有时候会非常的慢,有时达到不可接受的程度 。
这是因为pip安装软件时,默认使用的是Python官方的镜像源
pip安装软件包时,默认使用的镜像源是:https://pypi.org/simple/
因为此镜像源不在国内,所以受网络影响较大,下载速度慢且易导致连接超时
常用国内镜像源| 维护单位名称 | 镜像源地址 |
|---|---|
| 清华 | https://pypi.tuna.tsinghua.edu.cn/simple |
| 阿里云 | http://mirrors.aliyun.com/pypi/simple/ |
| 中国科技大学 | https://pypi.mirrors.ustc.edu.cn/simple/ |
| 华中理工大学 | http://pypi.hustunique.com/ |
| 山东理工大学 | http://pypi.sdutlinux.org/ |
| 豆瓣 | http://pypi.douban.com/simple/ |
通过参数添加信任主机或指定源
- -i, --index-url 指定一个符合PEP 503的软件包存储库 base URL of the Python Package Index (default http://mirrors.aliyun.com/pypi/simple/). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.
- –extra-index-url 声明备用源 Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.
- –trusted-host 声明放开对非https地址源的访问限制 Mark this host as trusted, even though it does not have valid or any HTTPS.
使用示例如下:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pdfplumber pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pdfplumber pip install pillow -i http://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.python.org/simple --trusted-host mirrors.aliyun.com永久修改 windows
- 在用户目录下创建pip目录【如C:UsersABCpip】,并在此目录中创建pip.ini文件
- pip.ini文件内容如下:
[global] timeout = 6000 index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host=pypi.tuna.tsinghua.edu.cnLinux下
- 创建或修改~/.pip/pip.conf文件
- pip.conf文件的内容如下:
[global] timeout = 6000 index-url = http://mirrors.aliyun.com/pypi/simple/ [install] use-mirrors =true mirrors =http://mirrors.aliyun.com/pypi/simple/ trusted-host =mirrors.aliyun.com



