Python pip 加速
索引地址
https://gh-proxy.cn/pypi/simple
一键换源脚本
# root 改全局配置,普通用户改自己的配置
curl -fsSL https://gh-proxy.cn/scripts/pip.sh | sh
# 先看会改什么,再决定是否执行
curl -fsSL https://gh-proxy.cn/scripts/pip.sh | sh -s -- --dry-run
# 只给当前用户配置 / 还原到执行前
curl -fsSL https://gh-proxy.cn/scripts/pip.sh | sh -s -- --user
sh pip.sh --restore
手动配置
写入 ~/.config/pip/pip.conf(当前用户)或 /etc/pip.conf(全局):
[global]
index-url = https://gh-proxy.cn/pypi/simple
timeout = 60
也可以直接用命令写:
pip config set global.index-url https://gh-proxy.cn/pypi/simple
pip config list
临时使用(不改配置)
pip install -i https://gh-proxy.cn/pypi/simple requests
pip install -i https://gh-proxy.cn/pypi/simple -r requirements.txt
pip download --no-deps -d /tmp/pkgs -i https://gh-proxy.cn/pypi/simple requests
uv / pipx
UV_INDEX_URL=https://gh-proxy.cn/pypi/simple uv pip install requests
pipx install --pip-args="-i https://gh-proxy.cn/pypi/simple" ruff
验证
curl -sI https://gh-proxy.cn/pypi/simple/pip/ | head -1
pip config list
pip download --no-deps -d /tmp/pip-test six
常见问题
- 索引地址写错:结尾必须是
/simple,少写会返回 404; - 证书报错:本站使用正常 HTTPS 证书,不需要
--trusted-host;
若公司网络替换过证书,请让运维把根证书装进系统信任区; - 想恢复官方源:删除上面写的配置文件,或执行脚本的
--restore。