I’m working on a few django sites all at the same time, and keeping the PYTHONPATH environment variable set correctly was getting to be a pain, and virtualenv seemed like it took a lot to set up – or that’s the way it looked from all the other blog posts out there.
So I took the plunge, and I’m happy to say it didn’t take all that much effort to go from a homebrew environment hack to using virtualenv.
This works for me, but note, I have to use python2.5 (because of Google AppEngine) and I’m on OSX or ubuntu all day long.
sudo easy_install-2.5 virtualenv
That’s it. A lot simpler than I originally thought with all those other articles mentioning pip and zc.buildout.
It turns out using virtualenv is a lot easier than I thought also. A lot of the articles talk about using pip to install dependencies, etc. I’m sure pip is great and once I start rolling it out I’ll probably never look back. But for now I have a relatively small set of teams to manage, and everyone uses their own setup that works for them.
There’s only two setup steps and then you can use virtualenv. You don’t have to change your source control unless you really want to.
First, set up the new environment:
virtualenv --no-site-packages --python=python2.5 my_env_name
Then you activate the new environment:
Now you are running with an empty environment. You need to perform your dev environment setup in this python virtual environment. But you only have to do that once.
Switching environments just means sourcing the right activate script. After a couple of alias changes in bash I’m all set.