wx in a VirtualEnv (for RunSnakeRun)

Since I got asked about this in email I'll post it here for the google-verse. Say you want to allow your developers to use RunSnakeRun running in a virtualenv on an Ubuntu distribution.  You'll recall that normally to run RSR as a utility you do:

$ sudo apt-get install python-wxgtk2.8
$ pip install --user SquareMap RunSnakeRun
$ runsnake

That gets a bit more complex when you want to put RSR in a virtualenv (the question was actually how to make this work on many, many workstations using puppet, but you puppet peoples can figure that out). Building wxPython is not really a fun project, so I'm going to assume you likely want to use the binary package, but you want to make wx available to a virtualenv.  You've got a few options:

  • use the --system-site-packages flag when creating your virtualenv
  • build wxPython yourself using a prefix, add the appropriate LIBRARY env variable to load it (again, not a really fun project and you're stuck mucking about with your environment)
  • add the binary-package directory to your PYTHONPATH
  • create a .whl or bdist_dumb from the binary package contents (there doesn't seem to be an "installed-directory-to-wheel" command I could fine)
  • link the binary packages into your virtualenv

The one *I* normally use is the --system-site-packages flag, but the linking solution has the advantage of not pulling in *other* packages you don't want. It is accomplished like so:

    $ sudo apt-get install python-wxgtk2.8
    $ virtualenv -p python2.7 wxsetup
    $ ln -s $(/usr/bin/python2.7 -c "import wx,os; print 
os.path.dirname(os.path.dirname(wx.__file__))")/* 
wxsetup/lib/python2.7/site-packages/
    $ source wxsetup/bin/activate
    $ pip install SquareMap RunSnakeRun
    $ runsnake

Note: this depends on the wxPython binary on Ubuntu 12.04 being installed in a format where there is a directory which is added to the PYTHONPATH, in theory some other distribution might be adding the wx/wxPython directories directly to the site-packages/dist-packages path, in which case the above would link everything in site/dist packages into your virtualenv. You could make the code just print the wx and wxPython directories instead of their parent directory.

Note that wxPython Pheonix is apparently pip-installable.  Yay for that, but I haven't actually tried it yet.

Comments

Comments are closed.

Pingbacks

Pingbacks are closed.