4

Possible Duplicate:
Can I change an an existing virtualenv to ignore global site packages? (like --no-site-package on a new one)

I have a virtualenv set up, with plenty of packages installed that I don't want to reinstall. Is there a way to set up this existing virtualenv so that it does not use the global site-packages directory?

FYI, this is primarily motivated by getting this warning: UserWarning: Module X was already imported from every time I start up, e.g., mercurial.

Related, but doing the inverse: Revert the `--no-site-packages` option with virtualenv. This implies that all I need is a lib/no-global-site-packages.txt file, but an empty one of those seems to have no effect.

Community
  • 1
  • 1
keflavich
  • 18,278
  • 20
  • 86
  • 118

1 Answers1

4

See also for the inverse: Modifying a virtualenv.

For completeness I'll post the inverse instructions of my answer there. Eventually this question can be merged with the other one.

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

$ virtualenv $PATH_TO_VIRTUALENV

or on older versions where --system-site-packages was the default behaviour:

$ virtualenv --no-site-packages $PATH_TO_VIRTUALENV

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

Community
  • 1
  • 1
Pedro Romano
  • 10,973
  • 4
  • 46
  • 50
  • Tried this, but with python2.7 it tells me that I'm asking the wrong question... `The --no-site-packages flag is deprecated; it is now the default behavior.` And I'm still getting the UserWarning's. I'll probably accept this answer, since it's technically the right answer to mine in the title, but something is still awry. – keflavich Oct 24 '12 at 18:42
  • You are absolutely right. Revised the answer to the most correct one taking into account the default behaviour on recent versions. – Pedro Romano Oct 24 '12 at 18:53