I am installing packages from requirements.txt
我正在从requirements.txt安装软件包。
pip install -r requirements.txt
pip安装- r让
The requirements.txt file reads:
需求。txt文件写道:
Pillow
lxml
cssselect
jieba
beautifulsoup
nltk
lxml
is the only package failing to install and this leads to everything failing (expected results as pointed out by larsks in the comments). However, after lxml
fails pip
still runs through and downloads the rest of the packages.
lxml是唯一一个没有安装的包,这导致了所有东西的失败(larsks在评论中指出的预期结果)。但是,在lxml失败后,pip仍然运行并下载其余的包。
From what I understand the pip install -r requirements.txt
command will fail if any of the packages listed in the requirements.txt
fail to install.
从我所了解的pip安装-r需求。如果在需求中列出的任何包,txt命令将会失败。txt无法安装。
Is there any argument I can pass when running pip install -r requirements.txt
to tell it to install what it can and skip the packages that it cannot, or to exit as soon as it sees something fail?
在运行pip安装-r要求时,我能传递什么参数吗?txt告诉它安装它能做什么,跳过它不能做的包,或者在它看到什么东西失败后立即退出?
4 个解决方案
#1
80
Running each line with pip install
may be a workaround.
使用pip安装运行每一行可能是一个解决方案。
cat requirements.txt | xargs -n 1 pip install
Note: -a
parameter is not available under MacOS, so old cat is more portable.
注意:一个参数在MacOS下是不可用的,所以老猫更便携。
#2
4
The xargs
solution works but can have portability issues (BSD/GNU) and/or be cumbersome if you have comments or blank lines in your requirements file.
xargs解决方案可以工作,但是如果您的需求文件中有注释或空白行,可能会有可移植性问题(BSD/GNU)和/或很麻烦。
As for the usecase where such a behavior would be required, I use for instance two separate requirement files, one which is only listing core dependencies that need to be always installed and another file with non-core dependencies that are in 90% of the cases not needed for most usecases. That would be an equivalent of the Recommends
section of a debian package.
对于需要这种行为的usecase,我使用了两个单独的需求文件,其中一个只列出了需要经常安装的核心依赖项,另一个文件包含了90%的非核心依赖项,而这些都是大多数usecase所不需要的。这相当于debian软件包的推荐部分。
I use the following shell script (requires sed
) to install optional dependencies:
我使用以下shell脚本(需要sed)安装可选依赖项:
#!/bin/sh
while read dependency; do
dependency_stripped="$(echo "${dependency}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Skip comments
if [[ $dependency_stripped == \#* ]]; then
continue
# Skip blank lines
elif [ -z "$dependency_stripped" ]; then
continue
else
if pip install "$dependency_stripped"; then
echo "$dependency_stripped is installed"
else
echo "Could not install $dependency_stripped, skipping"
fi
fi
done < recommends.txt
#3
3
For windows:
windows:
# This code install line by line a list of pip package
import sys
import pip
def install(package):
pip.main(['install', package])
if __name__ == '__main__':
with open(sys.argv[1]) as f:
for line in f:
install(line)
#4
-8
Do you have requirements for lxml using? Here they are for install:
您对使用lxml有要求吗?这里是安装:
sudo apt-get install libxml2-dev libxslt-dev python-dev
If you use Windows or Mac, you can check that too. Alternatively, setting STATIC_DEPS=true will download and build both libraries automatically.(c)
http://lxml.de/installation.html
如果你使用Windows或Mac,你也可以检查一下。或者,设置STATIC_DEPS=true将自动下载并构建这两个库
#1
80
Running each line with pip install
may be a workaround.
使用pip安装运行每一行可能是一个解决方案。
cat requirements.txt | xargs -n 1 pip install
Note: -a
parameter is not available under MacOS, so old cat is more portable.
注意:一个参数在MacOS下是不可用的,所以老猫更便携。
#2
4
The xargs
solution works but can have portability issues (BSD/GNU) and/or be cumbersome if you have comments or blank lines in your requirements file.
xargs解决方案可以工作,但是如果您的需求文件中有注释或空白行,可能会有可移植性问题(BSD/GNU)和/或很麻烦。
As for the usecase where such a behavior would be required, I use for instance two separate requirement files, one which is only listing core dependencies that need to be always installed and another file with non-core dependencies that are in 90% of the cases not needed for most usecases. That would be an equivalent of the Recommends
section of a debian package.
对于需要这种行为的usecase,我使用了两个单独的需求文件,其中一个只列出了需要经常安装的核心依赖项,另一个文件包含了90%的非核心依赖项,而这些都是大多数usecase所不需要的。这相当于debian软件包的推荐部分。
I use the following shell script (requires sed
) to install optional dependencies:
我使用以下shell脚本(需要sed)安装可选依赖项:
#!/bin/sh
while read dependency; do
dependency_stripped="$(echo "${dependency}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Skip comments
if [[ $dependency_stripped == \#* ]]; then
continue
# Skip blank lines
elif [ -z "$dependency_stripped" ]; then
continue
else
if pip install "$dependency_stripped"; then
echo "$dependency_stripped is installed"
else
echo "Could not install $dependency_stripped, skipping"
fi
fi
done < recommends.txt
#3
3
For windows:
windows:
# This code install line by line a list of pip package
import sys
import pip
def install(package):
pip.main(['install', package])
if __name__ == '__main__':
with open(sys.argv[1]) as f:
for line in f:
install(line)
#4
-8
Do you have requirements for lxml using? Here they are for install:
您对使用lxml有要求吗?这里是安装:
sudo apt-get install libxml2-dev libxslt-dev python-dev
If you use Windows or Mac, you can check that too. Alternatively, setting STATIC_DEPS=true will download and build both libraries automatically.(c)
http://lxml.de/installation.html
如果你使用Windows或Mac,你也可以检查一下。或者,设置STATIC_DEPS=true将自动下载并构建这两个库