How to add existing files to project using Eclipse and PyDev

16,323

Solution 1

If it is not an Eclipse project, then you have to create a new Eclipse project in the root of the Django project.

Go to File menu, click New > Project.

Select Pydev Django Project, assuming you have added the PyDev and PyDev Django plugins to Eclipse. Click Next.

Give your project a name, then browse to the location where your Django project exists (where your manage.py, settings.py, and url.py is).

Select a Python Grammar to use (anything prior to 3 - there are some issues with 3 and Django).

Click Next, and Next again (don't need to reference other projects).

Enter database details and click Finish.

Your Eclipse/Django project is ready to go.

Solution 2

This is a moderately painful process, but I have gone through it in Kepler (Eclipse 4.3), with the recent Pydev version.

Assuming you have the sources somewhere on your system, not in the workspace folder.

  1. Install Pydev (Help > Install New Software...), use http://pydev.org/updates as the source.
  2. Create a new empty Pydev project. Name it how you want, but it can be like your actual application name.
  3. File > New > Other... - in Pydev choose "Link sources folder" or similar. Navigate to your sources folder, and select the target project that we just created.

Now you'll see the files in the tree ("Pydev Package Explorer"), will be able to edit etc, but you can't run this (manage.py runserver) or run unit tests (manage.py test).

To do this, right click the project and choose Pydev > Set as Django project (see here: http://pydev.org/manual_adv_django.html)

Now go to properties and configure the settings module, and path to your manage.py.

Caution: this is relative to your project directory in the workspace. Even if you type /path/to/my_django_project/manage.py.

So, I ended up doing this (bash):

$ cd $HOME/workspace/my_django_project
$ ln -s /path/to/my_django_project

and left the configuration as "my_django_project/manage.py" and "settings". (in Windows you could do the same within 1 Volume - using mklink /J)

Now, it all works like a dream - there is a "Django run configuration" for my project, the files get modified in the working copy checked out outside of workspace, unit test run nicely and all is fine. If I just were able to make Subclipse see my sources as a working copy, I'd be almost like on PyCharm (except for a Django Template syntax-highlighted autocompleting editor, richer code inspections, and the automatic recognition of such sources as a django project).

Share:
16,323
ballaw
Author by

ballaw

Updated on August 07, 2022

Comments

  • ballaw
    ballaw almost 2 years

    I'm fairly new to Eclipse and I have been trying to import a Django project I had made separate from Eclipse. It would be most helpful if someone could give me a step-by-step guide on how to import my Django project.

    All I was able to find was to import the file hierarchy but that led to either incomplete imports or importing folders I didn't want. Any help would be appreciated.

  • ballaw
    ballaw about 12 years
    How do you add a new file to the eclipse project that was created externally? For instance when you create a new Django app you can't do it from Eclipse? By the way I followed your instruction I got the error that it couldn't create the project because the files already existed.
  • Furbeenator
    Furbeenator about 12 years
    Okay, so it is an existing Eclipse project, then. I thought it was an existing Django project, without being an Exlipse project. For that you want to do an Import. 1) File > Import > General - Existing Projects into Workspace > Next 2) Select root directory: Browse to project location. 3) Finish
  • Furbeenator
    Furbeenator about 12 years
    To add existing files to an existing Eclipse project, you simply move the files to the project's location. If they are not showing up in Eclipse, right-click on the Eclipse project and click Refresh to rescan the folder where the project exists.
  • Tomasz Gandor
    Tomasz Gandor almost 10 years
    This may be some remedy for the last problem I stated: eclipse.kacprzak.org Not sure if it autocompletes well, but the colors are good enough.