摘要
Python包安装慢得让人崩溃?别让默认源拖垮你的开发效率!本文手把手教你配置清华TUNA等国内镜像源,彻底解决PIP下载卡顿问题。从临时加速命令到永久设为默认,再到PDM、Poetry及Homebrew的专属配置方案,覆盖多工具场景。掌握这些技巧,包安装速度飙升,开发效率立竿见影提升。告别等待,即刻解锁流畅编程体验——3分钟搞定,从此告别"pip install"的漫长煎熬!
— 文章内容摘要
临时使用
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple some-package注意,simple 不能少。
pip 要求使用 https ,因此需要 https 而不是 http
设为默认
升级 pip 到最新的版本后进行配置:
python -m pip install --upgrade pip
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
python -m pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade pip配置多个镜像源
如果您想配置多个镜像源平衡负载,可在已经替换 index-url 的情况下通过以下方式继续增加源站:
pip config set global.extra-index-url "<url1> <url2>..."请自行替换引号内的内容,源地址之间需要有空格, 例如:
pip config set global.extra-index-url "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"PDM
通过如下命令设置默认镜像:
pdm config pypi.url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simplePoetry
通过以下命令为单个项目设置首选镜像:
poetry source add --priority=primary mirrors https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/通过以下命令为单个项目设置补充镜像:
poetry source add --priority=supplemental mirrors https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/Poetry 尚未支持全局设置镜像。参考 issue 1632。
使用全局镜像的临时方案是将 Poetry 的安装器切换回 pip,如下所示。但该方式会在将来的版本中停止支持,参考 PR 7356。
poetry config experimental.new-installer falseHomebrew
本节主要供 Homebrew 帮助使用。
export HOMEBREW_PIP_INDEX_URL="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

评论(25)