mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4mobile wallpaper 5mobile wallpaper 6
558 字
2 分钟

pip永久换源和临时换源的方法

为什么要换源

因为在pip下载python包时由于服务器架设在国外这样国内访问掉包率和速度会很慢

后一种还好,前一种下载体积大的包不可避免会超时,这样就要用到国内的镜像源了

第一种(非永久改源)

这一种只需要在下载的包名后加一个“-i 镜像链接

下面是几个常用的镜像

清华大学:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:https://mirrors.aliyun.com/pypi/simple

中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple

豆瓣:https://pypi.douban.com/simple

那么命令就是

pip install 包名 -i https://mirrors.aliyun.com/pypi/simple

第二种方法(永久改源)

在“C:\Users\%username%\AppData\Roaming”目录下(或者直接在地址栏输入%username%

创建一个pip.ini

输入以下命令

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

其中链接index-urltrusted-host可以改为其他的镜像源

最好重启一下

应该就可以了

一些改源时候会遇到的问题

一部分的pip源链接可能是http格式的(不是https格式)这样下载时可能会出警告甚至报错

ERROR: Could not find a version that satisfies the requirement pandas (from versions: none)
ERROR: No matching distribution found for pandas
 

注意改为https格式的链接就行

部分镜像源的部分包的部分老版本可能会没有,如果下载不到相应版本还是换成官方的镜像源下载吧。

分享 如果这篇文章对你有帮助,欢迎分享给更多人!
pip永久换源和临时换源的方法
https://vmss.cn/posts/pip%E6%B0%B8%E4%B9%85%E6%8D%A2%E6%BA%90%E5%92%8C%E4%B8%B4%E6%97%B6%E6%8D%A2%E6%BA%90%E7%9A%84%E6%96%B9%E6%B3%95/
作者 木木em哈哈发布于 2023-06-06许可协议 CC BY-NC-SA 4.0

评论

距上次编辑: 2023-06-06 内容信息可能已经过时
上一篇用python爬取博客的图片链接(入个门)下一篇python爬虫“indexerror: list index out of range”错误及其解决办法

目录