python切换镜像源
在国内使用python官方源速度太慢,可以使用镜像源,本文以北师大镜像
为例说明镜像源的使用
- 个人体验来说,北师大镜像源速度要比阿里和清华的要快。
PyPI 镜像使用帮助
PyPI 镜像在每次同步成功后间隔 5 分钟同步一次。
pip
临时使用
1 | pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple some-package |
注意,simple
不能少, 是 https
而不是 http
设为默认
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
1 | python -m pip install --upgrade pip |
如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
1 | python -m pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple --upgrade pip |
配置多个镜像源
如果您想配置多个镜像源平衡负载,可在已经替换 index-url
的情况下通过以下方式继续增加源站:
1 | pip config set global.extra-index-url "<url1> <url2>..." |
请自行替换引号内的内容,源地址之间需要有空格
可用的 pypi
源列表(校园网联合镜像站):https://mirrors.cernet.edu.cn/list/pypi
PDM
通过如下命令设置默认镜像:
1 | pdm config pypi.url https://mirrors.bfsu.edu.cn/pypi/web/simple |
Poetry
通过以下命令设置默认镜像:
1 | poetry source add --priority=default mirrors https://mirrors.bfsu.edu.cn/pypi/web/simple/ |
通过以下命令设置次级镜像:
1 | poetry source add --priority=secondary mirrors https://mirrors.bfsu.edu.cn/pypi/web/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/
注意:新版 Ubuntu 要求使用https源。
参考
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 xd's blog!
评论