Reputation: 2000
How to use pip to install software to a specific virtualenv from outside the virtualenv.
For example if I have a virtualenv /home/guest/virtualenv/django-env, How to install python packages into /home/guest/virtualenv/django-env/lib/python2.7/site-packages/ without doing source /home/guest/virtualenv/django-env/bin/activate and by using the default pip available in /usr/local/bin/pip
The context is , I am doing remote installation of software using fabric , and when I am using fabric I am not able to persist newly created virtual env. Hence , to be able to install software into the new virtualenv I am having to run the default pip (/usr/local/bin/pip) from outside the virtualenv
Upvotes: 0
Views: 717
Reputation: 172209
You don't have to source a virtualenv to use it. Just install the package by executing the pip that is installed in the virtualenv: /home/guest/virtualenv/django-env/bin/pip install <package>
You can also in earlier version of pip, run pip in another virtualenv than the one it's installed in with pip -E
, like this:
pip -E /home/guest/virtualenv/django-env/
But that really has no advantage over the above, and could cause errors, so the first option is still better.
Upvotes: 2
Reputation: 2598
Previous to pip 1.1, there was an option -E to install packages inside an virtual environment without switching, like you can do,
pip install -E /path/to/env <package>
But according changelog,
Removed -E/--environment option and PIP_RESPECT_VIRTUALENV; both use a restart-in-venv mechanism that’s broken, and neither one is useful since every virtualenv now has pip inside it. Replace pip -E path/to/venv install Foo with virtualenv path/to/venv && path/to/venv/pip install Foo.
So if you have pip prior to 1.1, you're lucky to use the global pip.
Upvotes: 1