Showing posts with label virtualenv. Show all posts
Showing posts with label virtualenv. Show all posts

Wednesday, April 07, 2010

Pydev and virtualenv

A doubt that arises sometimes is how to use Pydev with virtualenv, so, here we go...

For those that don't know about it, virtualenv is a Python tool that allows one to configure a new Python interpreter that's 'sandboxed' based on an existing interpreter.

Sample use of virtualenv:

Say you have an interpreter in d:\bin\python26 (with easy_install in place).

You could do d:\bin\python26\scripts\easy_install.exe virtualenv to install virtualenv and later do:

d:\bin\Python26\Scripts\virtualenv.exe d:\bin\Python26django, which would create a new Python install at d:\bin\Python26django.

Later, you could add new libraries just at that Python install without disturbing the base install.

E.g.:
d:\bin\Python26django\Scripts\easy_install-2.6.exe django would install django at that interpreter without changing the default one.

Now, as far as Pydev is concerned, there's nothing special in configuring a regular interpreter or an interpreter available through virtualenv. It's just a matter of following the default steps (available at http://pydev.org/manual_101_interpreter.html) but pointing to the interpreter created by virtualenv (in this case d:\bin\Python26django\scripts\python.exe).

Note: For linux users, the instructions should be similar, but the created folder by virtualenv doesn't put the interpreter at a 'scripts' folder, but at a 'bin' folder.

Update: Note that when selecting a virtualenv interpreter, the folders from the base install won't come checked by default when adding the interpreter, so, those have to be manually selected.