pip3 国内下载太慢?手把手教你换清华源,速度飞起!🚀

是不是每次用 pip 安装 Python 包都像在等蜗牛爬?🐌 下载速度慢还总报错?别急!今天教你 3 分钟搞定清华源配置,下载速度直接起飞!✈️

🔧 配置全攻略

一、查看当前源(知己知彼)🔍

1
pip3 config list

👉 如果显示 index-url = https://pypi.org/simple 说明正在用官方默认源

二、临时使用清华源(应急必备)🚑

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

举个栗子 🌰:

1
pip3 install requests -i https://pypi.tuna.tsinghua.edu.cn/simple

三、永久配置清华源(一劳永逸)⚡

▎🖥️ Windows 用户看这里

  1. Win+R 输入 %APPDATA% 回车
  2. 进入 pip 文件夹(没有就新建)
  3. 创建 pip.ini 文件并添加:
    1
    2
    3
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host = pypi.tuna.tsinghua.edu.cn

▎🐧 Linux/macOS 用户这样做

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

四、懒人专用命令(推荐🌟)🤖

1
2
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 config set global.trusted-host pypi.tuna.tsinghua.edu.cn

💡 这行命令会自动帮你生成配置文件!

✅ 验证配置是否成功

1
pip3 config list

看到 https://pypi.tuna.tsinghua.edu.cn/simple 就说明成功啦!🎉

🚨 常见问题

为什么配置后还是慢?
👉 检查网络连接,尝试 ping pypi.tuna.tsinghua.edu.cn

安装时报证书错误?
👉 在配置文件中添加 trusted-host = pypi.tuna.tsinghua.edu.cn

如何恢复默认源?
👉 删除配置文件或注释掉相关配置即可

🌈 扩展小知识

清华大学镜像站还支持这些工具加速:

  • Conda
  • Docker
  • npm
  • Maven
  • 各大 Linux 发行版