Linking Platform Packages into VirtualEnv (automatically)?

So you're creating a virtualenv with --no-site-packages so that you get some package isolation for testing, but you want to have those 2-3 platform-provided packages included, numpy, PIL, maybe a DB adapter.  Is a script to create a symlink the best approach?  What about when you aren't in control of the virtualenv and you just want your package to depend on the "imported system package of" something so that easy_install/pip/whatever will automatically link the system package in?

Comments

  1. Rob

    Rob on 11/10/2009 9:39 a.m. #

    For the first problem you could use virtualenvwrapper (http://pypi.python.org/pypi/virtualenvwrapper).

    It allows you to define hooks at various points of your interaction with the virtualenv e.g. postactivate, prermvirtualenv, postmkvirtualenv and so you can easily setup a command that gets run everytime an environment is created. It also has a command add2virtual which takes the path to a lib and creates a .pth file which will include it in the env.

    Combine the two and you can have it so that after an env is created it automatically adds in PIL, MySQLdb or whatever else you need

  2. Marius Gedminas

    Marius Gedminas on 11/11/2009 12:57 p.m. #

    I'd love to be able to do something like

    $ virtualenv --no-system-packages venv
    $ venv/bin/inherit psysopg2 lxml
    $ venv/bin/easy_install Pylons SQLAlchemy

    where the hypothetical 'inherit' script creates the appropriate symlinks to system-wide packages.

Comments are closed.

Pingbacks

Pingbacks are closed.