53

On Ubuntu 16.04 with virtualenv 15.0.1 and Python 3.5.2 (both installed with apt) when I create and activate new Python virtual environment with

virtualenv .virtualenvs/wtf -p $(which python3) --no-site-packages
source .virtualenvs/wtf/bin/activate

I get the following output:

Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/das-g/.virtualenvs/wtf/bin/python3
Also creating executable in /home/das-g/.virtualenvs/wtf/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.

Indeed pip freeze --all lists these 4 packages:

pip==8.1.2
pkg-resources==0.0.0
setuptools==25.2.0
wheel==0.29.0

Though, I'd expect pip freeze (without --all) to omit these implicitly installed packages. It does omit some of them, but not pkg-resources:

pkg-resources==0.0.0

(Same btw. for pip freeze --local)

While this is consistent with the help text

$> pip freeze --help | grep '\--all'
  --all                       Do not skip these packages in the output: pip, setuptools, distribute, wheel

having pkg-resources in the pip freeze output doesn't seem very useful and might even be harmful. (I suspect it's why running pip-sync from pip-tools uninstalls pkg-resources from the virtual environment, subtly breaking the environment thereby.) Is there any good reason why pip freeze lists pkg-resources instead of omitting it, too? As far as I remember, it didn't list it on Ubuntu 14.04 (with Python 3.4).

das-g
  • 9,718
  • 4
  • 38
  • 80
  • I don't know why exactly this happens. This happened to me with a different package that was actually essential for my project. The solution I found was to edit the requirements.txt with the latest available version on PyPi. One possibility, I'm guessing, is the version that was initially installed is no longer available on PyPi. – owobeid Oct 01 '16 at 14:07
  • It's amazing that there isn't an answer for this yet... – Adam Oct 18 '16 at 12:45
  • This caused a production push to fail for me, so I am very curious as to the answer / resolution. – Craig Wright Oct 19 '16 at 19:39
  • 3
    I created a ticket, it may eventually provide an answer: https://github.com/pypa/pip/issues/4022 – Craig Wright Oct 19 '16 at 19:57
  • 5
    https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463 – Craig Wright Oct 21 '16 at 01:29
  • 1
    Debian bug report [#871790](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790) is also about this issue. – das-g Jun 01 '19 at 21:46
  • I recently this issue although both Ubuntu and pip have been fixed. I don't know why. I fixed it by removing the virtual environment and making a new one. You can find steps on how to do that online – Hemil May 28 '20 at 06:51

2 Answers2

40

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

Craig Wright
  • 3,220
  • 1
  • 21
  • 16
  • This affects Debian users too. Looks like the fix was made for Ubuntu [see the most recent comment of original bug report](https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463) and Debian ([#1](https://salsa.debian.org/python-team/modules/python-pip/-/commit/5ccaf859a5b168e65368b61aa47fec53f32a367c) [#2](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790)). – Mike Apr 16 '20 at 13:11
10

I had the same problem in my virtual environment. I removed it with pip uninstall pkg-resources==0.0.0

Phares
  • 1,008
  • 13
  • 20
  • 5
    Warning: This may subtly break your virtualenv. – das-g Jan 21 '18 at 12:05
  • @das-g In what way it may break virtualenv? – marcanuy Jan 08 '19 at 21:27
  • Sorry, I don't quite remember what the issue was back then, and I don't have an Ubuntu system handy at the moment. IIRC, `pkg-resources` is an integral part of the virtualenv and needed by Python, pip or maybe virtualenv itself. Not sure what exactly would stop working when it's missing. – das-g Jan 09 '19 at 08:50