pip 加速

pip 镜像加速

把 pip 的 index-url 指向本站,PyPI 索引与安装包都会通过本站代理下载。

● 兼容 pip / pip3 / uv ● 支持断点续传 ● HTTPS 证书正常校验

索引地址

推荐用脚本
index-url
https://gh-proxy.cn/pypi/simple

脚本会先备份原配置,之后可以随时还原:

默认:root 改全局,普通用户改自己
curl -fsSL https://gh-proxy.cn/scripts/pip.sh | sh

先预览会改什么

--dry-run
sh pip.sh --dry-run

还原

--restore
sh pip.sh --restore

只想给当前用户配置

--user
curl -fsSL https://gh-proxy.cn/scripts/pip.sh | sh -s -- --user

写入 ~/.config/pip/pip.conf(当前用户)或 /etc/pip.conf(全局):

pip.conf
[global]
index-url = https://gh-proxy.cn/pypi/simple
timeout = 60

或者直接改命令行配置

pip config
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

接口对照

GET /pypi/simple/<包名>/
包索引(HTML / JSON)
GET /pypi/files/<路径>
安装包下载
GET /pypi/packages/<路径>
安装包下载(备用前缀)

索引页里指向上游文件服务器的地址会被自动改写为本站地址, 因此 pip download 与它的缓存也能正常走镜像。

自检

shell
curl -sI https://gh-proxy.cn/pypi/simple/pip/ | head -1
pip config list
pip download --no-deps -d /tmp/pip-test requests
← 返回软件源加速