Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtualenv: global site-packages vs the site-packages in the virtual environment

  1. If I have a certain package installed both in the global site-packages and in the local one, which package will get imported? Will that even work or will I get an error?
  2. Which packages should I put in the global site-packages and which in the local one?
like image 961
Monika Sulik Avatar asked Dec 07 '09 14:12

Monika Sulik


People also ask

What are global site packages?

“Inherit global site packages” means that the packages installed on your computer (outside of the virtual environment) will be added to the virtual environment. Follow this answer to receive notifications.

What is the difference between virtualenv and VENV?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.

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).

What is virtualenv package?

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. You can install virtualenv using pip. Unix/macOS.


1 Answers

The previous answer wraps up question 1 but ignores question 2.

The general best practice I've seen for which packages to put globally:

First, the core Python packages, as these don't change with backwards-incompatible issues unless you're upgrading a major version, and you'll want whatever security fixes from a python upgrade to apply automatically to your virtualenvs.

Second, packages that are a pain to easy_install or pip install into each individual virtualenv but that don't change very often -- MySQLdb/psycopg and PIL, for example.

Pretty much everything else should go into your virtualenv's packages (I highly recommend using pip requirements files and virtualenvwrapper to make this minimally painful and easy to set up on other machines).

like image 77
Yoni Samlan Avatar answered Oct 11 '22 14:10

Yoni Samlan