218

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).

What is pkg-resources, and is it OK to remove this line from 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.

Community
  • 1
  • 1
elethan
  • 16,408
  • 8
  • 64
  • 87
  • *"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."*. Can you maybe give an example for that? – Dimitris Fasarakis Hilliard Sep 19 '16 at 16:58
  • @Jim, good point. I added the example that I ran into. – elethan Sep 19 '16 at 17:03
  • hm, what's your version of `pip`? I'm thinking this might of been something they missed in an old release since in `8.1.2` I have no entry for `pkg-resources`. (Which it shouldn't since I'm pretty sure `pkg-resources` comes with `setuptools`). – Dimitris Fasarakis Hilliard Sep 19 '16 at 17:25
  • @Jim My `pip` version is `8.1.2`. – elethan Sep 19 '16 at 17:28
  • Well, this is odd. I too am on `Ubuntu 16.04` with `pip 8.1.2` and *still* don't see it. – Dimitris Fasarakis Hilliard Sep 19 '16 at 17:56
  • 1
    @Jim it just occurred to me that it may be related to `virtualenv`, and indeed, when I am *not* in a virtualenv I don't see it either. This still does not explain what it is, but at least is a clue that I can investigate. – elethan Sep 19 '16 at 18:12
  • Dupe of https://stackoverflow.com/questions/38992194/why-does-pip-freeze-list-pkg-resources-0-0-0/40167000?noredirect=1#comment67602638_40167000 ? – Craig Wright Oct 21 '16 at 02:31
  • 1
    Possible duplicate of [Why does pip freeze list "pkg-resources==0.0.0"?](https://stackoverflow.com/questions/38992194/why-does-pip-freeze-list-pkg-resources-0-0-0) – Louis Mar 11 '19 at 17:13
  • This is almost certainly a duplicate of @CraigWright's ticket SO post. See [my comment on his post](https://stackoverflow.com/questions/38992194/why-does-pip-freeze-list-pkg-resources-0-0-0#comment108357289_40167000). They've fixed this for both Debian and Ubuntu installs. – Mike Apr 16 '20 at 13:16
  • still not fixed with ubuntu 18.04 – sudeepgupta90 Jul 08 '20 at 10:11

3 Answers3

251

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

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):

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

edit 2022 July 06:

I have been informed that the package name differs depending on the system in use (pkg-resources vs pkg_resources). Please see the comments attached to this answer for differences in usage between different versions of Debian/Ubuntu. As pkg-resources is the historically correct package name at the time this was posted (almost 6 years ago) for the system in question, it will remain unchanged in this answer.

Craig Wright
  • 3,220
  • 1
  • 21
  • 16
19

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.

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.

karlsebal
  • 1,449
  • 17
  • 23
  • Thanks for the info. I ended up removing it too and have not seen any consequences either, but the same caveats you mention apply of course. Where you installing to/from a `virtualenv` as well? – elethan Sep 22 '16 at 15:29
  • Yes, I tried installing from inside a virtualenv. Since systemwide package is present and I did not want to mess things up I did not try installing per pip systemwide. – karlsebal Sep 24 '16 at 11:14
1

I found an answer in this link: pip freeze includes "pkg-resources==0.0.0" in comment 10 by: Louis Bouchard (louis) posted: 2019-11-16:

It worked for me. But I'm not an expert so, if someone undestands it better, would be great if explained it.

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 .
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 viable workaround :

$ 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
$
moken
  • 3,227
  • 8
  • 13
  • 23
panxogol
  • 11
  • 1