Install python and pip first. Once the python is installed, we can start setup for virtual environment. (assuming you installed python3), 1- installing pip:
sudo apt-get install python3-pip
2- next, install virtual env
pip3 install virtualenv
3- Now, go to your project directory where you want to use virtual-env / your python version
cd /var/www/test-proj
4- and run following command to setup virtual environment:
virtualenv .
The above command will install virtual env in current folder test-proj
. While running above command, you can choose the python version you want to use for this project test-proj
. To choose the python version, instead of running #4 command virtualenv .
, run following command:
4a-
virtualenv -p /usr/bin/python2.7 .
which will create virtual env in current folder with python 2.7 5- Now, since the virtual env is installed, all we need to do it is to activate before using:
source venv/bin/activate
A more detailed guide is available on https://gist.github.com/Geoyi/d9fab4f609e9f75941946be45000632b