Skip to content

How To: Django+PyDev on Feisty

May 16, 2007

This is a how to/guide on setting up a Django development environment on Ubuntu 7.04 (Feisty Fawn) using Eclipse and PyDev. Here I assume that you start with a fresh install of Feisty, please adapt accordingly.

Install Eclipse and Django

Open the terminal and type these:

# sudo apt-get install eclipse
# sudo apt-get install python-django

Or you can just install them via the Synaptic Package Manager. It’ll try to install some extra packages, just accept them.

Install PyDev

Start Eclipse from the Appliactions menu (Applications > Programming > Eclipse)

  1. Help > Software Updates > Find and Install.
  2. Click on “Search for new features” to install and hit Next.
  3. Click on New Remote Site:
    1. Enter Name: “PyDev Extensions”
    2. Enter URL: http://www.fabioz.com/pydev/updates
    3. Click OK.
  4. Click Finish.
  5. Eclipse will then display the Updates window, click on PyDev for Eclipse and click Next.
  6. Accept the License, click Next then click Finish.

Eclipse will then automatically download the required files and install them for you. After that it will ask you to restart Eclipse, just say Yes.

A more detailed guide (with screenshots) is avalable at be found at Fabio’s website.

Setup PyDev

On Eclipse:

  1. Window > Preferences
  2. Expand on PyDev and select “Interpreter – Python”.
  3. Click on New and just type “/usr/bin/python” and click OK.
  4. A selection window appears, the default looks fine, click OK.
  5. The default selection should include the Django directory but does not work right away! Apperently the Ubuntu Django package uses some symlinks which PyDev doesn’t like. We need to add the python-django directory manually.
    Click on New Folder:

    1. Enter Location: “/usr/share/python-support/python-django/”
    2. Click OK.
  6. Click OK.

PyDev wil then load the python libraries. This might take a few minutes, PyDev is basically ready to go!

Create a Django Project

Now we will try to create a new PyDev/Django project on Eclipse:

  1. File > New Project
  2. Select Pydev, PyDev Project. Click Next
  3. Enter the project name: “MyProject”
  4. Click Finish

After this we will need to set-up the Django directory tree via django-admin. Open the terminal:

  1. cd ~/workspace/MyProject/src
  2. django-admin startproject mysite

We go back to Eclipse. Refresh the navigator window, your new django project tree should be shown now.

  1. Open manage.py
  2. Run > Run. This will display the “Create, Manage and Run Configurations” dialog.
  3. Enter main module: path to your project’s manage.py (i.e. ~/workspace/MyProject/src/mysite/manage.py)
  4. Click on the Arguments Tab
  5. Enter base directory: your Django project’s root (i.e. ~/workspace/MyProject/src/mysite)
  6. Enter Program Arguments: “runserver --noreload” (there are two dashes)
  7. Select Interpreter: Default Interpreter
  8. Click Apply, Click Run

Open Firefox and try to access http://localhost:8000/ you should see the Django welcome page. To stop the Django server, click on the red button on your Console view (or tab). To re-run the server, press Ctrl+F11.

Fuih~ that was long. If you find any mistakes or questions, feel free to notify me.
Have Fun!

About these ads

From → Django, Ubuntu

18 Comments
  1. Isn’t pydef already available in feisty repository? Unless you want to try the latest version of pydef right?

  2. @imtheface:
    That is correct! PyDev is in fact available in the repository, but I prefer the latest and greatest. The Eclipse updater will install the updates in your home directory anyway and it won’t mess up with the system files. So it’s safe :)

  3. susiloharjo permalink

    jango itu apa toh :)

  4. @susiloharjo:
    Django itu adalah framework untuk membuat web application dengan Python. Silakan di cek di websitenya: http://www.djangoproject.com/

  5. Christopher permalink

    Great tutorial…but my system hangs up on the last step.

    When telling manage.py to “run”, I receive the error: “unable to get location for run”

    I believe your instructions are missing several vital steps here:

    1. Open manage.py
    2. Run > Run
    3. Click on the Arguments Tab
    – this opens a window “create, manage and run configurations”; Double click “Python Run”, which creates a new configuration.
    -Main Tab
    -Project: “MyProject”
    -Arguments Tab (see below)
    -Other tabs and info? Don’t know…

    4. Enter Program Arguments (Argument tab/”program arguments” field): “runserver –noreload”
    5. Click Apply, Click Run

    I’m sure something is still missing. Can anyone help?

  6. Small typo…

    # Enter URL: http://www.fabioz.com/pydev/update

    Should end with an “s” like so:

    # Enter URL: http://www.fabioz.com/pydev/updates

  7. @Christopher:
    Here is my settings on the “Create, Manage and Run Configurations” dialog (Arguments Tab):

    Base Directory: Path to Django project (e.g. /workspace/MyProject/src/mysite)
    Arguments: runserver –noreload
    Interpreter: Default Interpreter

    And I didn’t make any changes to the other tabs. Thanks for the input I’ll update the tutorial.

    @Gabriel:
    My mistake! I’ll fix that right away.

  8. Thomas permalink

    My system hangs also on the last step (same like Christophers message).
    I need the additional setting:
    Main Tab -> Main Module: Path to Django project/manage.py (e.g. /workspace/MyProject/src/mysite/manage.py)

    Using Debian Edge / Python 2.4 / Django 0.95 / Eclipse 3.2.1 / Pydev 1.3.4

    Thanks for the tutorial. It helps me a lot.

  9. @Thomas:
    Hmm.. I thought that the “Main Module” section is auto-filled. It looks like that I was wrong. Thank you very much for the update.

  10. Hi,
    I used django 0-96 from djangoproject website and one have to use:
    django-admin.py startproject mysite
    instead of
    django-admin startproject mysite

    Beside that it worked perfectly for me.

  11. @Robert:
    You could actually get Django 0.96.1 packaged for Ubuntu at: https://launchpad.net/ubuntu/gutsy/i386/python-django/0.96-1
    It is packaged for Gutsy but it works just fine on Feisty (I tried).

  12. Intricity permalink

    Thanks for posting this. It has saved many hours of hair-pulling and wading through scattered documentation all over the web. :)

  13. Hi,

    Should I have selected Eclipse 2.4? I selected 2.5 and have the same problem with: unable to get location for run. But when I type any path to “Main module”, eclipse says “The file in the location is not actually a file” and does not react to “Apply”. Also the “Browse” button is disabled. Running Feisty.

  14. I meant to say, when creating the project, should I have selected Python 2.4? Anyway, switching to it doesn’t help. I guess it’s an eclipse bug or has something to do with some other plugin, I’ve got quite many. :/

  15. diperlukan permalink

    Worked like a charm with me! Thanx, excellent tutorial man!!!

  16. Kaspar Hauser permalink

    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.

    :-)

  17. Shani permalink

    I am doing configuration of pydev + dejango. I have add the Arugument ” runserver –noreload” and when i tried to run it, it gave me following exception

    C:\Program Files\Google\google_appengine\lib\django\django\core\management.py:12: DeprecationWarning: the sets module is deprecated
    from sets import Set as set
    Traceback (most recent call last):
    File “E:\Java\Django\mysite\mysite\manage.py”, line 11, in
    execute_manager(settings)
    File “C:\Program Files\Google\google_appengine\lib\django\django\core\management.py”, line 1670, in execute_manager
    execute_from_command_line(action_mapping, argv)
    File “C:\Program Files\Google\google_appengine\lib\django\django\core\management.py”, line 1607, in execute_from_command_line
    action_mapping[action](addr, port, options.use_reloader, options.admin_media_path)
    File “C:\Program Files\Google\google_appengine\lib\django\django\core\management.py”, line 1179, in runserver
    from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    File “C:\Program Files\Google\google_appengine\lib\django\django\core\servers\basehttp.py”, line 14, in
    from django.utils._os import safe_join
    ImportError: No module named _os

    please guide me how to resolve this problem. Thanks in advance

Trackbacks & Pingbacks

  1. links for 2009-05-20 | UnderCo(n)struction.eu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: