Thursday, April 7, 2011

Python's virtual environment

You probably would like to use separate sets of packages for your projects and whilst not to spoil your system's environment. This problem can be solved by using virtual environments.

Make initial setup:


To configure virtualenvwrapper:

  1. Create a directory for the virtual environments:
    mkdir ~/projects/.envs
  2. Add to ~/.bashrc:
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    export WORKON_HOME=~/projects/.envs
    export PROJECT_HOME=~/projects
    
    source /usr/local/bin/virtualenvwrapper.sh
  3. Run:
    source ~/.bashrc

Initial setup has been done. Now let's create a new virtual enviroment for Test project in ~/projects/test
mkvirtualenv test
workon test
Now you're in the 'test' environment. To install new packages you can use, for instance, pip.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.