Fabric is a great tool for running system commands on a remote machine. It also has functionality for running commands locally. If all you needed to do is run local commands, then there probably are better options.
Since I needed to do both, I thought one fabfile with local and remote commands would be simplest. Unfortunately the “local” command and virtualenvwrapper do not play well together. Here is the magic to get them to work together:
local('source /usr/local/bin/virtualenvwrapper.sh && mkvirtualenv my_env', shell='/bin/bash')
Also, it is important to note that with fabric, the “local” command is not just a local version of the “run” command. The context manager (prefix) does not work with “local”. Neither does the “cd” command (use lcd).
I suppose I should also mention that you should not run this fabfile from inside a virtualenv. mkvirtulenv changes the virtualenv which leads to errors like:
/home/me/.virtualenvs/meta/bin/python: No module named virtualenvwrapper