修改 pip 源为国内镜像源
由于网络原因,直接使用 pip 默认源会很慢得可怕,这里提供一些国内的镜像,你可以选择使用:
- 阿里云:https://mirrors.aliyun.com/pypi/simple/
- 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
- 豆瓣(douban):http://pypi.douban.com/simple/
- 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
- 中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/
你可以在使用 pip 时通过 -i 参数指定使用上述源:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
如果想要永久修改,可以在 pip 配置文件中设置。配置文件位置和名称取决于操作系统:
- Linux/Unix:
~/.pip/pip.conf - Windows:
%APPDATA%\pip\pip.ini(%APPDATA%指C:\Users\用户名\AppData\Roaming)
若文件不存在,则需手动创建。
配置文件内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
对于使用 http 的源,可以选择性地加上 trusted-host 以信任它,避免出现警告信息。例如:
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
这样配置后,你每次使用 pip 安装包时都会默认使用这个源。
版权声明:本文为 阡陌 的原创文章,遵循「CC BY-NC-SA 4.0」版权协议。若转载,请附上本文链接及本声明。
本文地址:https://www.mculoop.com/archives/231.html
若对本文有疑问可在评论区留言,我们看到后会尽量解答。