Set virtualenv on Python projects

Sometimes we need different python packages versions in different projects. It’s like to have 3 computers, and running a different Python project on each computer, and the first project is using Django 1.8, the second project Django 1.7, and the third project Django 1.9.4.

Really I need 3 different computers to do that? Not at all.

Virtualenv is the hero, downloadable from pip, and it make our life easier. It let us to have a lot of Python projects, using their different dependence and versions, all living at the same computer but different environment. Check out the next image.

To install virtualenv, just you need to type:

pip install virtualenv 

This line will download, install and config virtualenv and their own dependence.

Now we are enabled to create a new virtual environment over any existing Python project. For this example, we already have a project called “mall4g”. We need to browse to the directory and run the command, where “mall4g” is a directory.

virtualenv mall4g

This will create extra directories:  lib, bin, include, local. Probably you want to ignore that directories when you push your code to Git.

Now, to activate:

source bin/activate

Done. Now, all python packages installed by using pip, will be located automatically under our “local” directory. No stress. No more problems.