2

After creating a fresh folder and creating a virtual environment

$ virtualenv venv --distribute

And installing two packages

$ pip install Flask gunicorn

Then writing all of the current pip installed packages to a file

$ pip freeze > requirements.txt
$ cat requirements.txt
Flask==0.10.1
Jinja2==2.7
MarkupSafe==0.18
Werkzeug==0.9.1
distribute==0.6.34
gunicorn==17.5
itsdangerous==0.22
wsgiref==0.1.2

I get this longer than expected list of packages, who is responsible for them being installed and what are they used for? The package list in question:

wsgiref==0.1.2
itsdangerous==0.22
distribute==0.6.34
MarkupSafe==0.18

I've used pip mostly on my Ubuntu box, and didn't have these packages installed after identical commands, I've noticed this behaviour only on my mac.

Morgan Wilde
  • 16,795
  • 10
  • 53
  • 99

3 Answers3

4

wsgiref and distribute are always present in the virtualenv, even an "empty" one where you have not yet pip install'ed anything. See the accepted answer to my question Why does pip freeze report some packages in a fresh virtualenv created with --no-site-packages? for an explanation. Note this is a bug fixed in Python 3.3.

itsdangerous and MarkupSafe are relatively recent, new dependencies pulled in by newer Flask releases.

  • itsdangerous (docs) is required by Flask directly. Since version 0.10 - see the github commit which added this dependency.
  • MarkupSafe (docs) is required by Jinja2 which is required by Flask. Jinja2 added this dependency in its version 2.7 - see the github commit.

You say that these are not installed on your Ubuntu box after running identical commands. But what version of Flask and Jinja2 do you have there? If they are older than the versions on your Mac, that might explain why they didn't pull in these new dependencies.

Community
  • 1
  • 1
Day
  • 9,465
  • 6
  • 57
  • 93
  • You're absolutely right, my experience with Ubuntu Flask is not as recent, so both dependencies seem to have been added sometime after that. Brilliant answer! – Morgan Wilde Jul 16 '13 at 05:55
1

it looks like those are Flask dependencies, (or dependencies of the flask dependencies)

pip install --no-install --verbose Flask

I was hoping pypi had a list of dependencies for each project, but I didn't see them...

dm03514
  • 54,664
  • 18
  • 108
  • 145
  • Indeed, thanks! Though there are two dependencies still left unexplained `wsgiref` and `distribute` – Morgan Wilde Jul 15 '13 at 15:36
  • 1
    @MorganWilde Indeed. That's a bug. See [my answer](http://stackoverflow.com/a/17665936/445073) – Day Jul 16 '13 at 00:07
1

Your virtualenv uses the packages installed system wide, so pip sees them along your newly installed ones.

Try adding the --no-site-packages option when creating your environment.

Or, try to explicitly run the pip instance installed in your environment (path/to/your/env/bin/pip opts...), maybe this will tell pip to ignore system's packages (not sure about that one at all).

Day
  • 9,465
  • 6
  • 57
  • 93
astrognocci
  • 1,057
  • 7
  • 16
  • Could you elaborate a bit on your point "venv uses packages installed system wide"? I personally don't remember installing any packages system wide, unless by accident... Is there a way to check what's installed system wide @astrognocci? – Morgan Wilde Jul 15 '13 at 15:39
  • 1
    @Morgan Wilde: to check whats installed system wide, just do pip freeze while not in a virtualenv (pip needs to be installed on the system too. apt-get install python-pip on a debian like machine). I had some issues with this a while ago, I was trying to install nosetests inside a venv and pip, detecting the system's one, just aborted instead of getting a new instance of it. I think dm03514 got the right answer, tho. – astrognocci Jul 15 '13 at 15:45
  • Thanks for indulging me, one more observation - after checking my system wide pip's, I did see far more of them than made the list in my question. How would you explain that if your original premise is - pip sees all of them along newly installed ones? @astrognocci – Morgan Wilde Jul 15 '13 at 15:50
  • I'll admit i'm still confused about this, and my answer is probably wrong. I just ran a global pip freeze from within a virtual env, and while it certainly doesn't list ALL global packages, it does list django or request, which i have NOT installed in this env. The trouble with installing nosetests led me to believe it would list them all, but there's apparently more to it. – astrognocci Jul 15 '13 at 16:06
  • It seems so, oh well, it still was stimulating, your answer. Good luck in your efforts! – Morgan Wilde Jul 15 '13 at 16:24