Using Virtualenv in Python
Virtualenv is a tool to create isolated Python environments. This may be useful if :
- You need to test some module
- You are doing a project that makes use of a different version of a package that is already installed.
So, I am installing pygame on my ubunutu and don't want this installation to be system-wide. Therefore I decided to use virtualenv.
To make a virtualenv,
- Go to the parent directory and open terminal in that directory.
- Type virtualenv --no-site-packages <<a folder name>>
- Then cd to the folder and type source bin/activate
This will create a virtual environment where you can install new python modules without the fear of it affecting the main python installation.
When your work is over, you can close the virtualenv using deactivate.
When your work is over, you can close the virtualenv using deactivate.
UPDATE
If your system has multiple versions of python, you can use any of those for creating the virtualenv. Like this
virtualenv -p /usr/bin/python3 venv