elethan elethan - 10 months ago 49
Python Question

Install certain packages in all virtualenvs

Recently I have started to use

, and it has changed my life, and made so many things so much easier. However, some packages I would like available in all virtualenvs, and I haven't figured out how to do this. Is there a way to have pip install certain packages every time I create a new virtualenv?


While the other answers to this question are both very valuable and informative, I was looking for a solution similar to that suggested by @Sergey Gornostaev. However, I am on Ubuntu and install most of my Python packages (at least the ones I want available globally) through apt. That means my packages end up in dist-packages while site-packages remains empty, so I can't use @Sergey's solution. Instead, I used the solution in this answer.

Basically, I install the packages I want available in all environments through apt if possible. Then I add the following (or some variation of it) to my .bashrc:

export PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages

This way all those packages are available, and then I can install indivdual packages sepecifc to a given virtual environment through pip from within the virtualenv. It might not be an ideal solution, but it meets my current needs, so this is what I will be using for now.