Important: this article is not released under a Creative Commons license and may not be copied or redistributed in any form. Please use our contact page to get in touch with us if you wish to reproduce the article.

Create your virtual development environments with virtualenv


Bharath Thiruveedula's Gravatar

Bharath Thiruveedula
published Sept. 14, 2013, 10:31 a.m.


Whenever we create a project or downloaded from GitHub, installing the required dependencies will create a lot of problems, because the versions of same software will conflict sometimes or if you want to test the new Python module which is not trusted may create serious problems. So, instead of installing as standard library install it in some sandbox like thing here we called it as "Virtualenv". Virtualenv will create a isolated development environment where we can test new modules or to create a project of certain versions which does not conflict with systems software. Let's have a look at it: <pre> 1. First of all install easy_install and pip: sudo apt-get install python-essentials (this will create easy_install) sudo easy_install pip 2. Now install our hero virtualenv pip install virtualenv </pre> Here we used pip tool, which make our lives easier while installing python modules. So, now we have installed virtualenv. Now let's look at how we can create virtual environment.

<pre> bharath@bharath-Inspiron-N5010:~$ virtualenv 2buntu New python executable in 2buntu/bin/python Installing distribute...........................................................................................................................................................................................................................done. Installing pip................done. bharath@bharath-Inspiron-N5010:~$ source 2buntu/bin/activate (2buntu)bharath@bharath-Inspiron-N5010:~$ </pre>

Have you checked the "(2buntu)" if you see that, then congratulations we have created our isolated development environment. Now install any python library it won't install system wide and your system won't crash anymore. But one warning don't install python module using "sudo" command, because if you use that then it will install globally.

Ok, Now we have our sandbox, how we can see the modules that are installed in our virtualenv. No problem Install yolk

<pre> (2buntu)bharath@bharath-Inspiron-N5010:~$ pip install yolk Downloading/unpacking yolk Downloading yolk-0.4.3.tar.gz (86kB): 86kB downloaded Running setup.py egg_info for package yolk Successfully installed yolk Cleaning up... (2buntu)bharath@bharath-Inspiron-N5010:~$ yolk -l Python - 2.7.4 - active development (/usr/lib/python2.7/lib-dynload) argparse - 1.2.1 - active development (/usr/lib/python2.7) distribute - 0.6.34 - active pip - 1.3.1 - active wsgiref - 0.1.2 - active development (/usr/lib/python2.7) yolk - 0.4.3 - active </pre>

Now yolk -l will show the installed modules in our virtualenv.

Happy Hacking :)