如何在出错后继续安装以下软件包?

时间:2017-05-17 17:35:21

标签: python-3.x pip

我需要安装文件中包含的几个依赖项,如下所示:

appdirs==1.4.3
asgiref==1.0.0
attrs==16.3.0
autobahn==0.17.2
Automat==0.5.0
Beaker==1.8.1
bleach==2.0.0
boto==2.46.1
boto3==1.4.4
botocore==1.5.26
channels==1.0.3
chardet==2.3.0
click==6.7
constantly==15.1.0
cssselect==1.0.1
cupshelpers==1.0
cycler==0.10.0
Cython==0.25.2
daphne==1.0.3
decorator==4.0.11

我试过了:

pip3 install -r list.txt

问题是该命令在发生错误后被破坏,如下所示:

  Downloading click-6.7-py2.py3-none-any.whl (71kB)
    100% |████████████████████████████████| 71kB 3.0MB/s 
Collecting constantly==15.1.0 (from -r list.txt (line 14))
  Downloading constantly-15.1.0-py2.py3-none-any.whl
Collecting cssselect==1.0.1 (from -r list.txt (line 15))
  Downloading cssselect-1.0.1-py2.py3-none-any.whl
Collecting cupshelpers==1.0 (from -r list.txt (line 16))
  Could not find a version that satisfies the requirement cupshelpers==1.0 (from -r list.txt (line 16)) (from versions: )
No matching distribution found for cupshelpers==1.0 (from -r list.txt (line 16))

由于我需要安装多个依赖项,我想忽略这些情况并继续安装缺少的依赖项,所以我真的很感谢支持找到这个选项,

1 个答案:

答案 0 :(得分:1)

xargs参数解决了这个目的。您可以参考以下代码:

#!/bin/sh

while read requirements_file; do
dependency ="$(echo "${requirements_file}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
if pip install "$dependency"; then
    echo "$dependency is installed correctly"
else
    echo "Could not install following dependency"
    fi
done < list.txt

这将尝试逐行安装依赖项,如果出现任何故障,它将转移到下一个依赖项。