Python pip freeze 命令的输出中的“pkg-resources==0.0.0”是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39577984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is "pkg-resources==0.0.0" in output of pip freeze command
提问by elethan
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 CItries to install dependencies through pip
and finds this line).
当我运行时,pip freeze
我看到(在其他预期的包中)pkg-resources==0.0.0
。我看到一些帖子提到了这个包(包括这个),但没有解释它是什么,或者为什么它包含在pip freeze
. 我想知道的主要原因是出于好奇,而且,在某些情况下,当尝试安装包含该行的requirements.txt
文件的包时,它似乎会破坏事情(例如,当Travis CI尝试通过安装依赖项并发现此线)。pip freeze
pkg-resources==0.0.0
pip
What is pkg-resources
, and is it OK to remove this line from requirements.txt
?
是什么pkg-resources
,可以从 中删除此行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 freeze
我在virtualenv
. 我仍然不确定它是什么或它做什么,但我会进一步调查,知道它可能与virtualenv
.
回答by Craig Wright
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 提交了一个后续错误。https://bugs.launchpad.net/ubuntu/+source/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 中删除该行应该是安全的。这是一个示例 Make 文件节,它可以安全地冻结您的包列表(放入您的 Makefile 并使用 运行make freeze
):
freeze:
pip freeze | grep -v "pkg-resources" > requirements.txt
回答by karlsebal
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 上开发时遇到了同样的问题,要求非常严格。在运行"pip install -r requirements.txt"
pip的 debian 8.5 上部署时,会抱怨“未找到”pkg-resources,但安装了全局包“python-pkg-resources”,因此应该满足依赖关系。在 ubuntu 上也一样:这个包也存在那里。
As stated hereit 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 上,删除那行应该是安全的。我这样做了,一切都运行良好。但是,由于我不是这方面的专家,因此您应该记住,在另一台机器上部署时,这可能会导致并发症。
回答by panxogol
found this answer in this link: https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
在此链接中找到此答案:https: //bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
by: Louis Bouchard (louis) wrote on 2019-11-16:
作者:Louis Bouchard (louis) 在 2019-11-16 上写道:
It worked for me. But I? not an expert so, if someone undestend it better, would be great if explained it.
它对我有用。但是我?不是专家所以,如果有人更好地理解它,如果解释它会很棒。
Hello,
你好,
for what it's worth, the problem comes from the debianized version of virtualenv which uses a debundled version of pkg_resource which gets added into the virtualenv at creation time :
对于它的价值,问题来自 virtualenv 的 debianized 版本,它使用 pkg_resource 的分拆版本,该版本在创建时添加到 virtualenv 中:
$ virtualenv .
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/caribou/git/quividi/test/bin/python2
Also creating executable in /home/caribou/git/quividi/test/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ pip freeze
pkg-resources==0.0.0
Using the pip installed version of virtualenv can be a workable workaround :
使用 pip 安装的 virtualenv 版本可能是一个可行的解决方法:
$ sudo apt -y purge python3-virtualenv virtualenv tox
$ pip install virtualenv
$ virtualenv .
pip install virtualenv
Collecting virtualenv
Downloading https://files.pythonhosted.org/packages/c5/97/00dd42a0fc41e9016b23f07ec7f657f636cb672fad9cf72b80f8f65c6a46/virtualenv-16.7.7-py2.py3-none-any.whl (3.4MB)
100% |████████████████████████████████| 3.4MB 351kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.7.7
$ virtualenv .
New python executable in /home/caribou/git/quividi/test/bin/python
Installing setuptools, pip, wheel...
done.
$ source bin/activate
$ pip freeze
$
hth, ...Louis
呃……路易斯
回答by ahmed
On Ubuntu, you can fix this by removing Ubuntu virtualenv
package and installing new version from pip
:
在 Ubuntu 上,您可以通过删除 Ubuntuvirtualenv
包并从pip
以下位置安装新版本来解决此问题:
sudo apt remove virtualenv
sudo pip install -U virtualenv