Setting up your python environment

If you’ve worked with python but never used virtualenv, then you will probably have encountered this problem. You are working on 2 projects. One requires version X of a library; the other requires version Y of the same library.

So you use virtualenv to create isolated python environments so you don’t have messy and conflicting dev environments in your system.

But here’s another tool that’s a bit easier to use. It’s a wrapper for virtualenv called virtualenvwrapper.

Here’s the basics.

Download it

pip install virtualenvwrapper

Now add these 2 lines to your ~/.bash_profile (if you’re on OSX)

export WORKON_HOME=~/virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

(Note, the 2nd line may be different depending on where virtualenvwrapper was installed)

Create a virtual env

mkvirtualenv env1

Exit from the virtual env

deactivate

Next time you want to work on that project again

workon env1

If you forgot what virtual envs you have created, you can list them

lsvirtualenv
Advertisements
Tagged , ,

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: