Getting started with virtualenv

Published: Sun 13 March 2011

In Tech.

tags: python

After switching to pip a while back ("pip uninstall", oh yeah!) I thought it was time to tame virtualenv, as pip and virtualenv tend to be introduced as the ideal way to work with Python nowadays. I started poking at it properly today, here's where I am so far.

$ pip -E mycoolenv install stuff

...That, does not really seem to work for me. Global dependencies still get picked up. I'll play with it more.

In the meantime, I've been doing the following. I'm sure it'll get more elegant and refined as I get used to the tool -- I'm writing this down now so I don't have to figure it all out again next week!

$ virtualenv --no-site-packages mycoolenv

This creates a folder "mycoolenv" with 3 subdirectories, bin, include and lib. After cd-ing into the new folder:

$ source bin/activate

Theoretically this changes your $PATH etc to point to the virtualenv bin/ directory. I don't think I've fully grokked it yet. I thought this meant if I run "python" it would now run it from mycoolenv/bin/python but that doesn't seem to be the case. So I'm linking to it manually in the meantime. [Update: Seems to work for me now, I was probably doing it wrong! 'which python' does link to the binary in the virtual env.] Then:

$ bin/pip install <all my dependencies>

For now this is enough for what I want to do, comparing different Django versions output (e.g. ../mycoolenv/bin/python manage.py runserver). Looking forward to learning more about it and using its full power!


Want to receive a weekly digest of new articles?

links

social