Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to isolate virtualenv from local dist-packages?

How do you stop virtualenv using '/usr/local/lib/python2.7/dist-packages'?

currently it when i run

virtualenv --no-site-packages ENV

it still uses the dist-packages that i wish to stop

EDIT: /usr/local/lib/python2.7/dist-packages is in the PYTHONPATH, it needs to be there for other apps

like image 740
Calum Avatar asked Jan 29 '13 20:01

Calum


People also ask

How do I list installed packages on VENV?

You can list only packages in the virtualenv by pip freeze --local or pip list --local . This option works irrespective of whether you have global site packages visible in the virtualenv .

Does virtualenv inherit packages?

If you build with virtualenv --system-site-packages ENV , your virtual environment will inherit packages from /usr/lib/python2. 7/site-packages (or wherever your global site-packages directory is).

How do I detach from VENV?

You can exit from the virtualenv using exit command, or by pressing Ctrl+d.

Can virtualenv access global packages?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects.


1 Answers

Your edit explains the behaviour you are observing.

You need to unset PYTHONPATH when activating the virtualenv.

unset PYTHONPATH
source /path/to/virtualenv/bin/activate

virtualenv --no-site-packages ENV creates an empty virtualenv just fine, but your PYTHONPATH export nullifies your empty virtualenv.

In order to make things simpler you can just edit the activate script and add the unset PYTHONPATH command there. If you want to restore the original PYTHONPATH upon deactivating the virtualenv you also need to modify the deactivate function in that file.

like image 72
bikeshedder Avatar answered Nov 27 '22 10:11

bikeshedder