Python 使用 pip 下载 “包” 默认使用官方的下载源,服务器在国外,国内下载一般比较慢,可以更换国内下载源解决。
一、源
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
二、临时更换
pip install 包名 –i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
三、永久方法
1、win + r 输入 %USERPROFILE% 进入用户文件夹(C:\User\用户名)
2、打开 pip 文件夹(没有则创建)打开 pip.ini 文件(没有则创建)
3、输入如下内容并保存
[global]
index-url=http://pypi.douban.com/simple/
trusted-host=pypi.douban.com
文件路径“C:\Users\用户名\pip\pip.ini”
四、常见问题
1、域名不可信
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=镜像站域名
临时则加上 --trusted-host 域名