Bio

Christopher Flynn

Webdeveloper, husband, dad, surfer, ameteur photographer, tinkerer, 2nd amendment advocate, brewer, chef, libertarian, atheist, UNIX Geek, troublemaker.


Virtualenvwrapper

I use virtualenv all the time to help keep python packages separate. This allows me to know what packages are required for any app I develop (by doing a simple pip freeze within a virtualenv) but also I can experiment with newer versions of packages for one application and not affect the others. It's great! What could make it better? Virtualenvwrapper.

Virtualenvwrapper by Doug Hellmann offers additional functionality for interacting with virtualenv. I'm not going to go over setting it up because he does a good job describing that on his site. Instead I'm going to offer some tips on how I use it.

First let's create a virtual environment:

$ mkvirtualenv myenv
New python executable in myenv/bin/python
Installing setuptools............done.

If everything is setup right you should see (myenv) in front of your prompt letting you know what virtualenv we are working in. You should also see messages about creating some activate/deactivate scripts. Let's edit one and add some stuff.

$ vi ~/.virtualenvs/myenv/bin/postactivate

Now this shouldn't have anything but some comments in it. Let's cd to our working directory and run git pull.

cd /path/to/code/
git pull

Save and exit and type 'workon myenv.' You should (assuming all the paths are correct and all) be changed into the directory and have git pull run for you. Type 'deactivate' to leave the environment. You could also add things to any of the scripts and this would largely depend on your workflow. The main advantage is you can type 'workon myenv' and you should be in your directory ready to go.

Also one final quick tip, typing 'workon' with no arguments will give you a list of your environments. This way if you forgot what you called it, you can easily see a list.

Comments

Comments are currently disabled for this post.

 
Christopher Flynn