python 更换 pip 镜像源

在安装 python模块时,如遇到下载速度慢的问题,可以通过 更换 pip 镜像源 来加速。以下是详细解决方案:


方法 1:临时使用国内镜像源

pip install 命令后直接指定镜像源(推荐清华源或阿里云):

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

或使用阿里云源:

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

方法 2:永久修改 pip 源

Windows 系统
  1. 打开用户目录(C:\Users\你的用户名),创建或修改 pip 文件夹下的 pip.ini 文件:
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host = pypi.tuna.tsinghua.edu.cn
    
  2. 保存后,所有 pip install 命令将自动使用清华源。
Linux/macOS

在终端执行:

mkdir -p ~/.pip
echo '[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn' > ~/.pip/pip.conf

方法 3:使用 --proxy 参数(如需代理)

如果网络需要代理,可指定代理服务器:

pip install pyqt6 --proxy=http://你的代理IP:端口

国内常用镜像源列表

镜像源名称 URL
清华源 https://pypi.tuna.tsinghua.edu.cn/simple
阿里云 https://mirrors.aliyun.com/pypi/simple
腾讯云 https://mirrors.cloud.tencent.com/pypi/simple
华为云 https://repo.huaweicloud.com/repository/pypi/simple
豆瓣源 http://pypi.douban.com/simple

为什么 PyQt6 下载特别慢?

  1. PyQt6 包含二进制依赖包(如 PyQt6_Qt6,文件较大(约 70MB+)。
  2. 默认的 PyPI 服务器在国外,国内直连速度较慢。

其他加速建议

  1. 使用 --timeout 延长超时时间
    pip install pyqt6 --timeout=600 -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  2. 分步安装依赖(先装小的包,再装大的):
    pip install PyQt6-sip -i https://pypi.tuna.tsinghua.edu.cn/simple
    pip install PyQt6-Qt6 -i https://pypi.tuna.tsinghua.edu.cn/simple
    pip install pyqt6 -i https://pypi.tuna.tsinghua.edu.cn/simple
    

验证是否生效

安装完成后检查版本:

python -c "from PyQt6.QtCore import QT_VERSION_STR; print(QT_VERSION_STR)"

应输出 6.9.0(当前最新版本)。


通过以上方法,下载速度通常可提升 10 倍以上!如果仍有问题,可能是网络限制,可尝试切换其他镜像源或使用代理。

你可能感兴趣的:(我的学习笔记,python,pip,开发语言)