Make Virtualenv Use Packages From Global Site Packages

Generally virtualenv does not use any python packages aleady present in the global site packages, but what if you want to use them?

Creating a virtualenv which includes all the python packages installed on the system is simple. Use the --system-site-packages flag when creating the new virtualenv as follows:

virtualenv --system-site-packages

You can now activate the virtualenv and install packages as usual.

If you want to override a system package for some reason you can use the --ignore-installed or the -I parameter with pip install. That way pip will install what you’ve requested locally even though a system-wide version exists.

pip install --ignore-installed

or

pip install -I

Note: By using -I, you will always reinstall packages, even if they already exist in the systemwide site-packages directory. If you use -U instead, it will install newer versions of packages into your virtualenv, but won’t reinstall any packages that are already available in the system with the required version.

Commands executed within the virualenv will only affect the packages within the virtualenv and will not make any changes to the packages installed globally.