How to install python virtualenv?


How to install python virtualenv?

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.

install virtualenv on Ubuntu

If you don't installed pip then visit https://learnbatta.com/blog/how-to-install-pip-in-ubuntu-linux-18/ and install PIP and to install virtualenv exexute the below commands.

sudo pip install virtualenv
# or
sudo pip install https://github.com/pypa/virtualenv/tarball/master

install virtualenv on Windows

If you don't installed pip then visit https://learnbatta.com/blog/install-pip-on-windows-16/ and install PIP and to install virtualenv exexute the below commands.

pip install virtualenv
# or
pip install https://github.com/pypa/virtualenv/tarball/master

usage of virtualenv

How to create virtual environment?

# create python2 virtual environment
virtualenv env2
# create python3 virtual environment
virtualenv -p python env3 

How to activate virtual environment ?

source env3/bin/activate
# or
. env3/bin/activate

How to install a python package in virtualenv ?

(env3) pip install django

How to deactivate virtual environment ?

(env3) deactivate

Reference:

https://virtualenv.pypa.io/en/latest/

{% include 'adsense/responsive_text_adds.html' %}

Read Next: How to install sublime text on Ubuntu ( Linux)

Read Prev: How to Install pip in Ubuntu (Linux)

Blog Archive