有什么方法可以强制 pip install 在需求安装失败时重试?

ghe*_*iev 4 python git pip gitlab

我正在尝试在我构建的容器中安装一些 pip 要求。但是由于我的设置(docker build 在通过 VPN 连接到 git 服务器所在网络的系统上的 VM 中运行。COVID-19 情况)我收到以下错误。我知道问题是由我的设置引起的,因为有时工作正常。另外,如果我在与 git 服务器位于同一网络内的机器上运行相同的 docker build,也可以正常工作。我花了一些时间试图找出我的网络问题,但还没有找到任何合适的解决方案。所以知道有一段时间 pin install git clone 工作,我想知道是否有任何方法可以指示 pip 重试安装失败的组件,直到它成功?

这就是我调用 pip install 的方式:

pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
Run Code Online (Sandbox Code Playgroud)

git lab repo URL 在 requirements.txt 中正确定义

谢谢

Collecting git+https://gitlab%2Bdeploy-token-98:****@git.my.host.com/core-tech/tools/nlu/trsx-converter.git@0.0.3 (from -r requirements.txt (line 19))
  Cloning https://gitlab%2Bdeploy-token-98:****@git.my.host.com/core-tech/tools/nlu/trsx-converter.git (to revision 0.0.3) to /tmp/pip-req-build-t8m2io14
  Running command git clone -q 'https://gitlab%2Bdeploy-token-98:****@git.my.host.com/core-tech/tools/nlu/trsx-converter.git' /tmp/pip-req-build-t8m2io14
  fatal: unable to access 'https://git.my.host.com/core-tech/tools/nlu/trsx-converter.git/': The requested URL returned error: 511                                                                                                       
ERROR: Command errored out with exit status 128: git clone -q 'https://gitlab%2Bdeploy-token-98:****@git.my.host.com/core-tech/tools/nlu/trsx-converter.git' /tmp/pip-req-build-t8m2io14 Check the logs for full command output.      
Run Code Online (Sandbox Code Playgroud)

Eli*_*iot 5

命令中有一个--retries选项pip install

pip install --help

General Otions:

  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
Run Code Online (Sandbox Code Playgroud)

这是5默认设置,所以我不确定它是否真的能解决您的问题,但您可以尝试使用更高的值,以防万一。

  • 现在如果有什么方法也可以设置指数退避就好了。 (2认同)