Home > Linux, Python > Setup Python Virtual Environment

Setup Python Virtual Environment

When working on multiple python projects, perhaps we need to isolate package dependencies that needed for each project, so that dependency changes on one project does not make other project stop working.

Here’s example how to setup python virtual environment on linux mint.

$ sudo apt-get install python-pip
$ pip install setuptools virtualenv virtualenvwrapper

Add following code in ~/.profile

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh

Execute following command

$ source ~/.profile

Done! It’s time to test.

  1. Create Virtual Environment for project 1: eg env1 (skip this if env1 already created)
    $ mkvirtualenv env1
  2. Activate virtual anvironment (eg: env1)
    $ workon env1
  3. Install package dependencies to current environment (eg: django)
    (env1)$ pip install django
  4. To get info about installed package:
    (env1)$ pip freeze
  5. Deactivate to exit from current virtual environment
    (env1)$ deactivate
  6. Get available virtual environments
    $ workon
  7. Remove virtual environment
    $ rmvirtualenv env1

     

Advertisements
Categories: Linux, Python
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: