解决pip安装慢的问题

解决pip安装慢的问题

在我们直接使用Python下载各种包的时候速度较慢

主要原因如下:

pip 默认从PyPI下载包,其主服务器位于欧美地区,国内访问时网络延迟高,跨国带宽有限,导致下载速度慢甚至超时。

解决方法

国内很多高校和科技公司提供了PyPI镜像站,使用国内源可以解决pip速度慢的问题,这里以清华源为例

方法1:临时使用(单词安装)

pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple

方法2:永久修改(修改pip默认源)

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

常见问题

镜像源不同步:部分镜像更新可能有延迟,弱安装失败,可临时切换为官方源

pip install 包名 -i https://pypi.org/simple

证书错误:如果遇到SSL错误,尝试添加 --trust-host指令

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

posted @ 2025-06-22 00:03  AttaSayyid  阅读(347)  评论(0)    收藏  举报