fabric, local and virtualenvwrapper

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s