Is it possible to install --no-site-packages in virtualenv after it is already configured?

Possible duplicate:
Is it possible to modify an existing virtualenv to ignore global site packages? (e.g. --no-site-package on new)

I have a virtualenv setup, with many packages that I don’t want to reinstall. Is there a way to configure this existing virtualenv so that it does not use the global package sites directory?

FYI, this is primarily motivated by receiving this warning: UserWarning: Module X was already imported from every time I run, for example, mercurial.

Associated, but the opposite is true: Cancel the option `--no-site-packages` with virtualenv . This means that all I need is the lib/no-global-site-packages.txt file, but the empty one seems to have no effect.

+4
source share
1 answer

See also for the opposite: Modifying a virtual file .

For completeness, I will send back the instructions of my answer. In the end, this question can be combined with another.

Since --no-site-packages is the default behavior in recent versions ( > = 1.7 ), you just need to recreate virtualenv with the command:

 $ virtualenv $PATH_TO_VIRTUALENV 

or in older versions where --system-site-packages was by default:

 $ virtualenv --no-site-packages $PATH_TO_VIRTUALENV 

replacing $PATH_TO_VIRTUALENV with the path to the existing virtualenv. This will reinstall virtualenv, reconfigure it to prevent access to global packages, keeping the packages already installed there.

+4
source

Source: https://habr.com/ru/post/1441871/


All Articles