2012-11-07

How to create a virtual environment that also uses global modules

Last weekend I upgraded my Mac to Mountain Lion. I installed Python 2.7 with PIL and MySQLdb and virtualenv using MacPorts.

When I created and activated a virtual environment with

cd myproject
virtualenv .
. bin/activate

the PIL and MySQLdb modules were unrecognizible in that environment. What I needed was just different Django versions in my virtual environments, but MySQLdb and PIL libraries had to be shared.

After a quick search I found an additional parameter for the creation of virtual environment:

virtualenv --system-site-packages .

With this parameter I could use my global modules within the virtual environment.

3 comments:

  1. When using virtualenvwrapper, check add2virtualenv command to add specified packages:

    http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html#add2virtualenv

    ReplyDelete
  2. The reason for this is that in the latest version of virtualenv the --no-site-packages flag it set by default.

    ReplyDelete