Virtual Environments in Python, Operating system Linux

What is Virtual Environment ?

A Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects or Operating system dependencies as All operating systems has python dependencies.

It also helps in maintaining version compatibility e.g Django 1.4 is recommended to be used with python2.7 whereas Django 1.5 or 1.6 can use python 3.x, so in virtual environments developers can keep compatible setups in isolated form in same operating system with different versions of python.

How to Install ?

<code>
$ pip install virtualenv
</code>

Since “pip” is not a system package, it is a python package manager command line tool. To Install “pip” use following command:

<code>
$ sudo apt-get install pip
</code>

How to create virtual environment ?

Developers can use following command to set up any number of virtual environment:

<code>
$ virtualenv my_environment_name
</code>

How to activate and deactivate virtual environment ?

Change into your virtual environment folder through command line:

To Activate:

code>
$ cd my_environment_name
</code>
<code>
$ source bin/activate
</code>

To Deactivate:

<code>
$ deactivate
</code>

Once we have activated our virtual environment e.g through command line we can see this –> ” (env) ” in the very beginning of command line which simply indicate that we are now in an isolated location of python where we can keep packages, code frameworks, entire application, javascript, style sheets and media which can not and not going to alter or affect other process or projects running in python.
Thats it.