My instructions for creating a Django Virtual Environment which works with Eclipse are as follows;
Note: The instructions are for OSX Mountain Lion, but should work with other operating systems. I have collated this information from various sources and would appreciate any suggestions or comments. I will assume you have python, virtualenv and eclipse set up on your system.
Open a terminal, move to the location you would like to have your eclipse workspace and;
- mkdir projectenv
- cd project env
- virtualenv venv --distribute
- source venv/bin/activate
Now, lets install the dependencies;
- pip install Django psycopg2 dj-database-url (Your needs may vary from mine)
Now we will start the Django project and commit to git;
- django-admin.py startproject myproject
- pip freeze > requirements.txt
- git init; git add; git commit -m myproject (Please have a .gitignore file with venv and *pyc in it before doing this step)
Our django project is set up and ready to go, so now open eclipse and at the workspace selector, click browse and select the projectenv folder (i.e. the folder which contains the venv folder, the myproject folder and the requirements.txt folder) and click open.
Go to File, Import, General, Existing Folder as New Project and select the myproject folder, click finish. Your project will now appear in the package explorer - you should now switch to the PyDev perspective if not already on it.
Right click on the main myproject folder in the package explorer, go down to PyDev and select 'Set as PyDev project'. Eclipse will now prompt you to set up the interpreter and will take you to the preferences window. Click New, and select the interpreter in /venv/bin/ select python, not python2.7 and click ok.
You will get a list of libs, leave them as they are and click finish, you will get a warning, but click proceed anyway.
Now, click on New Folder in the bottom half of the prefs window and select /venv/lib/, click ok, then click apply, then click ok.
Finally, right click on manage.py and Run As, Run Configurations. In the Arguments tab, type;
then click Apply and then Close.
That should be that, when you want to add an app, do so on the command line as you normally would using manage.py startapp myapp (if you install the Aptana Studio plugin, you can get a terminal window inside eclipse), right click the main project folder in eclipse and hit refresh, everything will be there. When you want to debug, set your breakpoints, hit Debug As python manage.py (the config you set up earlier) and when you hit a code breakpoint, Eclipse fires you into the debug perspective.
I find this gives me the perfect mix, it means I can write a lot of stuff on the command line as normal, but because it's set up in Eclipse, when things aren't going my way, I can fire up eclipse and do some real debugging!
I hope this helps.