I started by reading the overview, and it seems to be straightforward... now on to something real: downloading it... it says it only needs python, but I didn't find information on which is the preferred version. I googled for it and it appears that it is still not working well with python 2.5, so, I'll go with python 2.4.

Second step: install

[C:\bin\Python24]python e:\Install\Dev.Python\Django-0.95\setup.py install>> The required version of setuptools (>=0.6c1) is not available, and can't be installed while this script is running. Please install a more recent version first.

The tutorial says that it will attempt to grab setuptools if setuptools is not there, but unfortunatelly it seems it does not upgrade if a version is already there.

It also requires a database (as I'm just testing, pysqlite seems a good option -- I'm using version 2.3.0)

Now, on to re-configure the pydev interpreter to add those new paths... I'm kind of lazy, so, usually I just remove the interpreter and add it again, instead of figuring out just the new paths (I also thinks it's safer, as it gets all the folders it finds in the pythonpath automatically). More info on that at http://www.fabioz.com/pydev/manual_101_interpreter.html

Now, on to the actually doing something

To create a base project it provides a script, so let's do it:

django-admin.py startproject mysite

It created a 'mysite' folder with some files... still in the command line (inside the mysite folder), it says to start django with:

python manage.py runserver

And voila... it's running. Now, on to do that from inside Eclipse.

Eclipse requires your code to be under a project, so, the 'new pydev project' wizard should be used, pointing the project contents to the 'mysite' folder or to a parent folder. As there is usually much more than just code in a project -- like folders for python, c++, docs... and as in this example we surely won't have a c++ folder, the initial project structure became:/mysite /docs /src /mysite "import mysite" as the src is added to the pythonpath)

Now, on to starting the server from within pydev:If you just run the manage.py file (just open it and press F9), it will show you a message with its usage, so, run it once and then go to the menu: Run > Run... and select the 'mysite manage.py' run and put in the program arguments runserver.

Now, running it like that leaves us without any prompt inside of the Eclipse console. Taking a closer look in the django code, it appears to have an autoreloader structure (I guess that's something common to web-servers), so, as it is actually run in another process, we won't have any output. To fix this in the testing environment (after killing the process inside of Eclipse and the other process that is still running in the computer), we can just add another argument, so, now as arguments we have runserver --noreload

Note that the Eclipse console currently does not have a Ctrl+Break, so, you have to actually kill it in the red button in the console, and to re-run the last run, just use Ctrl+F11.

Now, on to set the sqlite parameters and create the actual database -- according to the tutorial, just set the engine and file to be used for sqlite and the on to:

python manage.py syncdb

-- I usually do that stuff on a separate prompt, as it is nice to run things inside of Eclipse, but having to change the argument for each different run is not all that nice (so, an open shell is always welcome)

and created a superuser... if you configured the auto-refresh for Eclipse as in http://www.fabioz.com/pydev/manual_101_eclipse.html, a new file should be appearing in the database file for sqlite -- if you pointed it to some file inside of your project (if you still haven't the auto-refresh configure, I really advise doing it, as it can be a pain having to F5 for it to refresh the folders when some external change is done to the filesystem)

Now, keeping on with the tutorial:

python manage.py startapp polls

and copied the example from the homepage. Defining the model seems straightforward, and code-completion / code-analysis should be already working ;-)

Making the syncdb again updates my sql with the new structure (pretty nice).

Now, adding the admin interface seems pretty straightforward, and without the auto-reload, the regular debugger works pretty well -- test it by putting a breakpoint after creating the __str__ function for the Poll class in the example and pressing F11 (used to debug the last run). If you want to keep the auto-reloader and still debug, you'll have to use the remote debugger that comes with the extensions to debug, as it does not rely on having the process started from Eclipse. Check http://www.fabioz.com/pydev/manual_adv_remote_debugger.html for more details.

And I guess that's it for the pydev configuration... code-completion, code-analysis, debugger, etc. should all be working.

28 comments:

Just an FYI, when running in the debugger, I had to set the base directory to the one containing settings.py, otherwise runserver wouldn't run. I did not have to do this when running without the debugger. So, I'm guessing the debugger starts in a different base directory.

You must have a source folder (but you can set the source folder to be in the project level, and not actually the 'src' folder) -- so, as long as you have your project pythonpath correctly set, you can have the structure that suits you better.

Thanks for this note. The one thing I can't get to seem to work is code-completion when it comes to the Django code. I've added Django to the PYTHONPATH and it looks like there's some sort of scanning going on, but when I try to add any code that references Django, for example in the polls/models.py, while adding:

votes = models.IntegerField()

I get no code assist, but if I reference something in the standard library, like:

Sorry, but what is this? Thoughts of a Programmer, written down in 30 Seconds? I could do that. Plz Make a clear, concize beginner-readable Text out of it or rename it to "Thoughts, flying through my Head while i configured pydev with Django"

some questions (i use win XP): Where does pydev store the pythonpath-Data? I have Paths there , which are not in my pythonpath, stored in the registry. Pythonpath, under ...HKEY_LOCAL_MACHINE/SOFTWARE/Python/PythonCore/2.5/PythonPath... contains:M:\bin\python25\Lib;M:\bin\python25\DLLs;M:\bin\python25\Lib\lib-tk

in Pydev (preferences/Interpreter - Python) there are more. Does Pydev search recursive the system Pythonpath ? (which, as far as i know, python itself doesnt)

i also have a Python.zip in my system32-Folder in the pydev listing of paths (that zip doesnt exist). What is it?

Whats the difference between "system libs" and "libs found in the pythonpath (dlls)"?

And, there are not just dlls, there are also pyds listed. Did u mean "libs found in the pythonpath (dlls and pyd)" ? Then why dont u write it?

So, this were the Questions i got from a few german Kids, while i tried to explain them the Pydev Configuration, together with django.

I couldnt answer the questions, can u ?

(and last, not least, pydev is a very nice tool and i enjoy working with it - thanks for it)

Well, yes... this is not intended to be a very detailed thing (that's why it's in this blog and not in the actual homepage)... But if you do have something more formal I'll gladly publish it in the appropriate space.

Now, on to your questions...

1. The pythonpath you see is the same that python uses... pydev spawns a shell and does:import sysfor p in sys.path: print p

The one in your registry is what python uses as the basis for that 'real' one (there are more ways to add paths to your pythonpath than through the registry, such as .PTH files or simply configuring your PYTHONPATH env variable).

Note that you can edit the pydev pythonpath to suit your needs (so you can add or remove libraries you want to use or not).

I don't know why python puts that .zip there (pydev just gets that info from the interpreter... you can just remove it without any problems)

2. Pyds are basically dlls (if you just rename a .dll to .pyd python will recognize it the same way), but that's different from platform to platform (e.g.: in linux it can be .so)... dll is to mean dynamically linked libraries (which can have any of those extensions).

3. System libs are the folders added to your pythonpath. The dlls is just more information for you to see (what appears there doesn't actually make any difference).

Great work, Fabio. Using your guide I can run the server from within Eclipse, and even use autocomplete. Unfortunately, my breakpoints and watches are completely ignored. It works correctly in WingIDE but I'd much prefer to use Pydev/Eclipse. Any ideas on what could be causing it? I followed your guide to the letter (several times).

p.s.: this blog is not the appropriate place for these doubts. Please ask at http://sourceforge.net/forum/forum.php?forum_id=293649 or report bugs following: http://pydev.sourceforge.net/faq.html#how_do_i_report_a_bug

For Debian or Ubuntu users, for which only an old and disfunctional version of pydev currently is available, simply install the available/prefered Eclipse, Python, Django and Pydev versions to meet all dependencies (you may have to use unstable repositiories if you cannot find Pydev in testing or stable).Then get the latest Pydev release (a zip containing org.python.pydev.*, com.python.pydev.* folders) from pydev.org. Copy that stuff to the appropriate folders, where also the old, above installed version is located (/usr/lib/eclipse/features and /usr/lib/eclipse/plugins). It should be obvious what belongs where.Restart Eclipse and the World should be perfect again.