On my current Django project we just moved away from using system-wide installed dependencies to using virtualenv. The transition is pretty straight forward and there’s a couple of good how-tos like this one. Out of the many good reasons to use virtualenv rather than installing the dependencies system-wide, I found those are the most important:
- projects with different dependencies are completely isolated from each other, no bad surprises if you install a new dependency for some other project
- no bad surprises if your os package manager decides to update a dependency
- dependencies can be defined within the project in a requirements file
- ability to quickly switch between different versions of dependencies
If you use the great Eclipse plugin PyDev as your IDE, here’s some simple steps to configure your project to use the virtual environment – assuming you’ve set it up already:
- In your virtual environment there’s a python wrapper that we want to use in Eclipse. Go to Window -> Preferences -> Interpreter Python and create a new interpreter. Select the python wrapper from the virtual environment ($WORKON_HOME/YOUR_PROJECT/bin/python). The libraries should be selected automatically – leave them as they are.
- In the project properties change the interpreter to use the newly created one (Project -> Properties -> PyDev Python Interpreter)
- Alternatively you can manage the environment individually for each run configuration in the ‘Run -> Run configurations -> Interpreter’ tab
This worked for me with Eclipse Helios SR2 and PyDev 1.6.5. To test it you could uninstall one of your dependencies from your system and install it only into that virtual environment. Some credit for the steps described goes to Luke Plant, however I tried to simplify it a bit.