pip 加速

pip 镜像加速

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

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

加速入口

点一下即可切换页面上的加速地址;延迟会按你的网络自动重测,带「推荐」的是对你最快的入口,页面示例默认就用它 查看详情 →

索引地址

一行命令即可切换
index-url
https://gh-proxy.cn/pypi/simple

直接写入 pip 配置文件(当前用户),不用下载脚本,一条命令完成切换:

切换镜像源
pip config set global.index-url https://gh-proxy.cn/pypi/simple

验证是否生效

查看当前配置
pip config list
pip config get global.index-url

想换回官方源

还原
pip config unset global.index-url

pip 3 及以上自带 pip config;非常老的版本请改用「一键换源脚本」或「手动配置」。 要给所有用户设置时,在命令前加 sudo 并补上 --global: sudo pip config set --global global.index-url https://gh-proxy.cn/pypi/simple

脚本由官网统一保存,切换加速入口时会自动补上参数;脚本会先备份原配置,之后可以随时还原:

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

先预览会改什么

--dry-run
curl -fsSL "https://www.gh-proxy.cn/scripts/pip.sh" | sh -s -- --dry-run

还原

--restore
curl -fsSL "https://www.gh-proxy.cn/scripts/pip.sh" | sh -s -- --restore

只想给当前用户配置

--user
curl -fsSL "https://www.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

各加速服务器的换源脚本

共 2 条

脚本仍然从官网拉取,只是用 ?node= 把加速地址固定到某台服务器上; 新增服务器后这里会自动出现对应的命令。

官网 · https://gh-proxy.cn
curl -fsSL "https://www.gh-proxy.cn/scripts/pip.sh?node=https://gh-proxy.cn" | sh
EdgeOne 加速 · https://eo.gh-proxy.cn
curl -fsSL "https://www.gh-proxy.cn/scripts/pip.sh?node=https://eo.gh-proxy.cn" | sh

接口对照

GET https://gh-proxy.cn/pypi/simple/<包名>/
包索引(HTML / JSON)
GET https://gh-proxy.cn/pypi/files/<路径>
安装包下载
GET https://gh-proxy.cn/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
← 返回软件源加速