There are a lot of pros to using a virtual environment to manage different Python environment, which will be independent of each other. The following are the steps to create one under Ubuntu 16.04 with Python 2.7.x
Install the virtualenv with the necessary packages
1 2 |
sudo apt-get install python-pip python-dev python-virtualenv sudo pip install -U pip |
Create a folder for the virtualenv
1 2 3 |
mkdir ~/envfolder/ cd ~/envfolder/ virtualenv --system-site-packages myenv |
Activate & Deactivate the virtual environment
1 2 |
yli@ubuntu:~/envfolder/myenv$ source bin/activate (myenv) yli@ubuntu:~/envfolder/myenv$ |
After sourcing the activate script, you can find a “(myenv)” in front of the folder prompt, which is the virtual environment’s name and it has been activated.
Now, the pip can be used to install/update the python modules belongs to this virtual env only.
To deactivate is also very simple.
1 2 |
(myenv) yli@ubuntu:~/envfolder/myenv$ deactivate yli@ubuntu:~/envfolder/myenv$ |