Saturday, 6 June 2015

Python How to Install and activate Virtualenv



How to Install and activate Virtualenv

1) Install virtualenv


           $ sudo apt-get install python-virualenv


2) Create virtual environment for our project

          $ virtualenv myenv


virtualenv venv will create a folder in the current directory which will contain the Python executable files. The name of virtualenv is "myenv".

3) To begin using the virtual environment, it needs to be activated

           $ source myenv/bin/activate





The name of the current virtual environment will now appear on the left of the prompt.Like this ,

(myenv)anusree@anusree-Inspiron-5547:~/my_project_folder$


If you want to install any python packages inside the virtual environment then do not use the command: "$ sudo apt-get install packagename".

I am going to show you install python package "django" inside the virtual environment "myenv" using command "$ pip install django" and don't  use     "$ sudo" command before "$ pip" command:

            $ pip install django


4) If you are done working in the virtual environment for the moment, you can deactivate it:

$ deactivate


The packages which i am installing into virtual environment "myenv" are stored in "myenv/lib/python2.7/site-packages"

In this screenshot you can see the package "django" i installed.