Virtualenv is a tool to manage the dependencies required by different projects. Imagine for a moment that you have written a program that works properly in Python version 2.7, and you do not wish to rewrite it to be compatible with Python version 3 (or whatever more recent version is the default interpreter). Virtual environments solve this problem by allowing you to create an isolated environment with the version and dependencies needed for that project, and keeping the global site-packages manageable.
For a more detailed introduction, refer to:
Create a virtual environment with the following command:
$ virtualenv my_project
This will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages.
You can also use the Python interpreter of your choice (python 2.7, for example).
$ virtualenv -p /usr/bin/python2.7 my_project
You can also create virtual environments using available system modules...
To begin using the virtual environment, it needs to be activated:
$ source my_project/bin/activate
From now on, any package that you install using pip will be placed in the my_project folder, isolated from the global Python installation. To use a virtual environment in an sbatch script, it can be activated with the above line. The script will automatically deactivate it upon completion.
Now it is possible to use pip to install additional libraries without having administrative access because pip will install into the virtual environment, and not into the system environment. Install packages as usual, for example:
$ pip install requests
If you are done working in the virtual environment for the moment, you can deactivate it:
$ deactivate
To delete a virtual environment, just delete its folder (In this case, it would be rm -rf my_project).