installation, python

What is virtualenv and why you should use it.

Have you ever heard of virtualenv ? The chances are that if you are a beginner then you might not have heard about it but if you are a seasoned programmer than it’s a vital part of your toolset. So what is virtualenv really ? Virtualenv is a tool which allows us to make isolated python environments. How does making isolated python environments help us ? Imagine you have an application that needs version 2 of a LibraryBar, but another application requires version 2. How can you use and develop both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

In another case just imagine that you have an application which is fully developed and you do not want to make any change to the libraries it is using but at the same time you start developing another application which requires the updated versions of those libraries. What will you do ? It is where virtualenv comes into play. It creates isolated environments for you python application and allows you to install python libraries in that isolated environment instead of installing them globally. In order to install it just type this command in the shell :

$ pip install virtualenv

Now i am going to list some of it’s commands. The most important ones are :

$ virtualenv ENV


$ source bin/activate

So what does these two commands do ? This first one makes an isolated virtualenv environment in the ENV folder and the second command activates that isolated environment. Now you can install any library without disturbing the global libraries or the libraries of the other environments. This was just a short intro to virtualenv. There’s a lot more to it. For further study i recommend this link. It will remove all of your confusions about virtualenv. I hope you liked today’s post. Do share your views in the comments below and stay tuned for the next post.



2 thoughts on “What is virtualenv and why you should use it.

  1. You should also check-out a project called zc.buildout. It’s similar to virtualenv but creates a Python environment sandbox in the directory where your project lives, and is based off “recipes” which can do things virtualenv can’t, building and installing non-python binaries locally (eg. libxml2). It’s very useful when you have a number of devs working on the same project across multiple systems, and makes deployment a breeze.

Leave a Reply

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

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