Search code examples
pythonpython-3.xpipubuntu-16.04

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


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.


Solution

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