52

When I create a fresh virtualenv, pip freeze shows that I have a couple of packages installed even though I've not installed anything into the environment. I was expecting pip freeze to return empty output until after my first pip install into the environment. wsgiref is part of the standard library isn't it, so why does it show up at all?

day@garage:~$ mkdir testing
day@garage:~$ cd testing
day@garage:~/testing$ virtualenv --no-site-packages .
New python executable in ./bin/python
Installing distribute..........................................................
...............................................................................
.........................................done.
day@garage:~/testing$ . bin/activate
(testing)day@garage:~/testing$ pip freeze
distribute==0.6.10
wsgiref==0.1.2

Some extra info:

(testing)day@garage:~/testing$ pip --version
pip 0.7.2 from /home/day/testing/lib/python2.7/site-packages/pip-0.7.2-py2.7.eg
g (python 2.7)
(testing)day@garage:~/testing$ deactivate
day@garage:~/testing$ virtualenv --version
1.4.9
day@garage:~/testing$ which virtualenv
/usr/bin/virtualenv
day@garage:~/testing$ dpkg -S /usr/bin/virtualenv
python-virtualenv: /usr/bin/virtualenv
day@garage:~/testing$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.04
DISTRIB_CODENAME=natty
DISTRIB_DESCRIPTION="Ubuntu 11.04"
Day
  • 9,465
  • 6
  • 57
  • 93

2 Answers2

44

Everytime you create a virtualenv with --no-site-packages it installs setuptools or distribute. And the reason wsgiref appears is because python 2.5+ standard library provides egg info to wsgiref lib (and pip does not know if it stdlib or 3rd party package).

It seems to be solved on Python3.3+: http://bugs.python.org/issue12218

Hugo Lopes Tavares
  • 28,528
  • 5
  • 47
  • 45
  • So is it safe to remove wsgiref? Thanks for the info! – Paolo Oct 05 '12 at 17:30
  • 1
    No, it is not safe to remove it, since `wsgiref` is part of the python standard library: http://docs.python.org/library/wsgiref.html – Hugo Lopes Tavares Oct 05 '12 at 17:53
  • 9
    Yes, you should not remove `wsgiref` itself. But it is safe to remove the `wsgiref` line from your [requirements.txt](http://www.pip-installer.org/en/latest/requirements.html) if you have generated that from the output of `pip freeze`. – Day Jan 09 '13 at 18:08
  • This is really strange. I created a fresh virtualenv and installed a few packages. When I did a `pip freeze` only the installed packages showed up. Two days later I installed some more packages and all of sudden `pip freeze` showed `distribute` and `wsgiref`. Why was it even clean in the first place?!? – Semmel Sep 27 '13 at 18:55
30

To answer a slightly different question: you can exclude wsgiref (and any other similarly-problematic .egg files if you are unfortunate enough to have any for some reason) by doing pip freeze -l instead of pip freeze.

pip help freeze describes this option:

-l, --local If in a virtualenv, do not report globally-installed packages

Day
  • 9,465
  • 6
  • 57
  • 93
Glyph
  • 31,152
  • 11
  • 87
  • 129