pip freeze 命令输出中的 "pkg-resources==0.0.0" 是什么

What is "pkg-resources==0.0.0" in output of pip freeze command

当我 运行 pip freeze 我看到(在其他预期的包中)pkg-resources==0.0.0。我看到一些帖子提到这个包(包括 ), 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 试图通过 pip 安装依赖项并找到这一行)。

什么是pkg-resources,是否可以从requirements.txt中删除这一行?

更新:

我发现当我处于 virtualenv 时,这条线似乎只存在于 pip freeze 的输出中。我仍然不确定它是什么或它做了什么,但我会进一步调查知道它可能与 virtualenv.

有关

关于你的问题“是否可以删除此行?”部分:

我在 ubuntu 16.04 上开发时也遇到了同样的问题,要求中也有这一行。在 debian 8.5 运行 "pip install -r requirements.txt" 上部署时,pip 抱怨 pkg-resources 是 "not found" 但安装了一个全局包 "python-pkg-resources" 因此应该满足依赖关系。在 ubuntu 上也一样:包也存在于那里。

如前所述,似乎有些"implicitly installed package"。

因此:如果您在 Debian/Ubuntu 上安装了 python-pkg-resources,删除该行应该是安全的 。我这样做了,一切正常 运行。但是,由于我不是这方面的专家,您应该记住,这可能会导致在另一台机器上部署时出现并发症。

根据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

为了备份之前的答案,从您的 requirements.txt 中删除该行应该是安全的。这是一个安全地冻结您的包列表的 Make 文件节示例(放入您的 Makefile 并 运行 和 make freeze):

freeze:
    pip freeze | grep -v "pkg-resources" > requirements.txt

在这个 link 中找到了这个答案:https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463

by: Louis Bouchard (路易斯) 于 2019-11-16 写道:

它对我有用。但本人不是专家,所以,如果有人更好地理解它,如果能解释一下就太好了。

你好,

就其价值而言,问题来自 virtualenv 的 debianized 版本,它使用 pkg_resource 的 debundled 版本,它在创建时被添加到 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

使用 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
$