Thursday, January 25, 2018

Python virtualenv Use

In development/testing environment;requirement of packages in different Python project is different.And other than this there is possibility that you needed different version of same packages for different projects.

To handle this situation one solution is virtualenv. Virtualenv project wise isolates your working copy of packages.

And its usage is quite simple

Installation
Firstly install virtualenv

#apt-get install virtualenv

Use/Activation
My project path is /home/sandeep/project1
then

#cd /home/sandeep/project1
#mkdir venv
#virtualenv venv

To active virtualenv

#source /home/sandeep/project1/venv/bin/activate

After that your your virtualenv foldername will be appeared in your cli(In our case it is venv;So it looks like this)

(venv)#
(venv)#pip install <pn>

After that activation;any package installation in this environment will be isolated to only this environment untill you deativate that.)

How to Deactivate
To deactivate virtualenv just type deactivate

#deactivate