解决 pipenv 安装第三方库时卡住(锁定依赖):更换国内源

  1. 问题描述
    准确来讲卡住的步骤不是在安装第三方库,而是在安装完成之后的锁定依赖的步骤。
    会出现类似下面的提示:

Locking [dev-packages] dependencies...
Locking [packages] dependencies...

最后报超时的异常
Read timed out.

    原因在于 Pipfile 文件中指定使用官方源锁定依赖,导致速度过慢,解决方案自然是更换国内源。
  1. 国内源的选择
    阿里云:http://mirrors.aliyun.com/pypi/simple/
    豆瓣:http://pypi.douban.com/simple/
    清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
    中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/

  2. 更换清华源
    注:以下过程在 Ubuntu 系统中进行,其他系统类似。

切换目录到项目文件根目录
查看 Pipfile 的内容: cat Pipfile

关注以下列:
[[source]]
url = "https://pypi.org/simple"

打开 Pipfile 替换 url 为国内源

[[source]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"

  1. 完成
    再次尝试 pipenv install 包名 ,这次锁定依赖时非常迅速。

Adding flask-login to Pipfile's [packages]...
Pipfile.lock (872fed) out of date, updating to (46e686)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock (46e686)!
Installing dependencies from Pipfile.lock (46e686)...
▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 16/16 — 00:00:07

你可能感兴趣的:(解决 pipenv 安装第三方库时卡住(锁定依赖):更换国内源)