How to install python virtualenv?¶
install virtualenv on Ubuntu¶
virtualenv is a python package. It is used to create an isolated python environments. virtualenv allows us to work with different versions of packages for different projects. when we work with projects, the requirements will change from project to project. If we use python package lets say celery==1.0 in some projects we may need to use celery==2.0. So, working with an isolated environment is a good approach to follow. When we install a python package in isolated environment it will only install in the virtual environment and It will not install as a global/system package. I allows us to maintain good development environment. We can use pip to install the python packages in the virtual python environment.
Note: If we install package without virtualenv then it will be install as a global package.
Steps to install virtualenv on ubuntu¶
If you didn't install pip then first install pip
- To install virtualenv on ubuntu run the below commands on terminal
sudo pip install virtualenv
# or
sudo pip install https://github.com/pypa/virtualenv/tarball/master
Steps to install virtualenv on Windows¶
If you didn't install pip on windows then first install pip
-
To install virtualenv on windows run the below commands on cmd
pip install virtualenv # or pip install https://github.com/pypa/virtualenv/tarball/master
usage of virtualenv¶
-
How to create virtual environment?
# create python3 virtual environment virtualenv -p python3 env
-
How to activate virtual environment ?
source env/bin/activate # or . env/bin/activate
-
How to install a python package in virtualenv ?
pip install django
-
How to deactivate virtual environment ?
deactivate