Skip to content

Virtual Environments: Simple Practical tools

Well apparently in this blog I’m concerned with root privileges and Python..! 😀

Again if you know your way around Python, then perhaps you would not need to read this post. However it might happen that you frequently use Python and do not know about this amazing tool/trick (which certainly was the case for me).

This simple yet sophisticated tool makes your life as python programmer a lot easier.

Good Practice Tip (you can skip this paragraph as it’s not related to this problem): Whenever you’re trying to code something in C/C++, in order to have some map or an “oracle” ,so to speak, it is good practice to first implement your algorithm using a higher level language. This helps you to have a tiny guide for debugging the original code. This especially proves useful for numerical optimization algorithms as well as parallel algorithms. I have used matlab and python throughout different projects before going to the powerful yet debug cumbersome C++. 

During my internship, in order to code some Deep Learning algorithms related to Hessian Free methods, I needed to use the package Theano, which can be used to symbolically take the gradients of mathematical expressions in python. The same old problem raised and since this package has many pre-requisites, taking the approach mentioned here would be much troublesome. Therefore the adventure to find a better way began.

Shortly I found a fascinating tool “VirtualEnv“. The documentation states:

virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.


Just what you need, a standalone python which is yours and you have the control over it..! Thus you don’t need any super privileges to install libraries or better yet you can have multiple python environments with different settings and packages. The steps to get and use this tool is quite easy:

1)Install it using PIP:

$ pip install virtualenv

2)Create a folder to contain the files regarding to virtual python instance . Running the second command creates the mentioned folder named “vpython”.

$ mkdir myPython && cd myPython
/myPython$  virtualenv vpython

3) To start using the new python

/myPython$ source vpython/bin/activate
(vpython) /myPython$ 

From now on any python runs or installations using pip will be done corresponding to the python copy located at vpython. Feel free to install any packages you like without any problems.!

After your work is done you can simply deactivate the active environment and get back to normal boring settings.!

$ deactivate