When I run pip freeze
I see (among other expected packages) pkg-resources==0.0.0
. I have seen a few posts mentioning this package (including this one), but none explaining what it is, or why it is included in the output of pip freeze
. The main reason I am wondering is out of curiosity, but also, it seems to break things in some cases when trying to install packages with a requirements.txt
file generated with pip freeze
that includes the pkg-resources==0.0.0
line (for example when Travis CI tries to install dependencies through pip
and finds this line).
当我运行pip冻结时,我看到(在其他预期的包中)pkg-resources==0.0.0。我已经看到一些文章提到了这个包(包括这个包),但是没有人解释它是什么,或者为什么它包含在pip freeze的输出中。我感到疑惑的主要原因是出于好奇,但在某些情况下,当试图安装带有需求的包时,它似乎会破坏一些东西。使用pip冻结生成的txt文件,其中包括pkg-resources= 0.0.0行(例如Travis CI试图通过pip安装依赖项并找到这行)。
What is pkg-resources
, and is it OK to remove this line from requirements.txt
?
什么是pkg资源,可以从requirements.txt中删除这条线吗?
Update:
I have found that this line only seems to exist in the output of pip freeze
when I am in a virtualenv
. I am still not sure what it is or what it does, but I will investigate further knowing that it is likely related to virtualenv
.
我发现这条线似乎只存在于pip冻结的输出中,当我在一个virtualenv中。我仍然不确定它是什么或者它做什么,但是我将进一步研究它可能与virtualenv相关。
2 个解决方案
#1
64
According to https://github.com/pypa/pip/issues/4022, this is a bug resulting from Ubuntu providing incorrect metadata to pip. So, no there does not seem to be a good reason for this behaviour. I filed a follow-up bug with Ubuntu. https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
根据https://github.com/pypa/pip/issues/4022,这是一个错误,因为Ubuntu向pip提供了不正确的元数据。所以,不,似乎没有一个好的理由来解释这种行为。我在Ubuntu上提交了一个后续bug。https://bugs.launchpad.net/ubuntu/ +源/ python-pip / + bug / 1635463
To backup the previous answer, it should be safe to remove that line from your requirements.txt. Here is an example Make file stanza that safely freezes your package list (drop in your Makefile and run with make freeze
):
要备份之前的答案,从requirements.txt中删除这一行应该是安全的。这里有一个示例Makefile stanza,它可以安全地冻结您的包列表(在您的Makefile中插入并使用Make freeze运行):
freeze:
pip freeze | grep -v "pkg-resources" > requirements.txt
#2
6
As for the part of your question "is it OK to remove this line":
关于你的问题“是否可以删除这条线”:
I have the same issue here developing on an ubuntu 16.04 with that very line in the requirements. When deploying on a debian 8.5 running "pip install -r requirements.txt"
pip complains that pkg-resources is "not found" but there is a global package installed "python-pkg-resources" so the dependency should be satisfied. Same on ubuntu: The package exists there as well.
在ubuntu 16.04上,我也遇到了同样的问题。当在debian 8.5上部署时,运行“pip安装-r要求”。pip抱怨说,pkg-resources“没有找到”,但是有一个安装了“python-pkg-resources”的全局包,因此应该满足依赖性。ubuntu也是一样:这个包也存在。
As stated here it seems to be some "implicitly installed package".
如此处所述,它似乎是一些“隐式安装包”。
So: If you are on a Debian/Ubuntu having python-pkg-resources installed it should be safe to remove that line. I did so and everything is running fine. However since I am no expert on this you should keep in mind that this might lead to complications when deploying on another machine.
所以:如果你在安装了python-pkg-resources的Debian/Ubuntu上,删除这一行应该是安全的。我照做了,一切都很顺利。但是,由于我不是这方面的专家,所以您应该记住,在另一台机器上部署时,这可能会导致复杂性。
#1
64
According to https://github.com/pypa/pip/issues/4022, this is a bug resulting from Ubuntu providing incorrect metadata to pip. So, no there does not seem to be a good reason for this behaviour. I filed a follow-up bug with Ubuntu. https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
根据https://github.com/pypa/pip/issues/4022,这是一个错误,因为Ubuntu向pip提供了不正确的元数据。所以,不,似乎没有一个好的理由来解释这种行为。我在Ubuntu上提交了一个后续bug。https://bugs.launchpad.net/ubuntu/ +源/ python-pip / + bug / 1635463
To backup the previous answer, it should be safe to remove that line from your requirements.txt. Here is an example Make file stanza that safely freezes your package list (drop in your Makefile and run with make freeze
):
要备份之前的答案,从requirements.txt中删除这一行应该是安全的。这里有一个示例Makefile stanza,它可以安全地冻结您的包列表(在您的Makefile中插入并使用Make freeze运行):
freeze:
pip freeze | grep -v "pkg-resources" > requirements.txt
#2
6
As for the part of your question "is it OK to remove this line":
关于你的问题“是否可以删除这条线”:
I have the same issue here developing on an ubuntu 16.04 with that very line in the requirements. When deploying on a debian 8.5 running "pip install -r requirements.txt"
pip complains that pkg-resources is "not found" but there is a global package installed "python-pkg-resources" so the dependency should be satisfied. Same on ubuntu: The package exists there as well.
在ubuntu 16.04上,我也遇到了同样的问题。当在debian 8.5上部署时,运行“pip安装-r要求”。pip抱怨说,pkg-resources“没有找到”,但是有一个安装了“python-pkg-resources”的全局包,因此应该满足依赖性。ubuntu也是一样:这个包也存在。
As stated here it seems to be some "implicitly installed package".
如此处所述,它似乎是一些“隐式安装包”。
So: If you are on a Debian/Ubuntu having python-pkg-resources installed it should be safe to remove that line. I did so and everything is running fine. However since I am no expert on this you should keep in mind that this might lead to complications when deploying on another machine.
所以:如果你在安装了python-pkg-resources的Debian/Ubuntu上,删除这一行应该是安全的。我照做了,一切都很顺利。但是,由于我不是这方面的专家,所以您应该记住,在另一台机器上部署时,这可能会导致复杂性。