Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add existing files to project using Eclipse and PyDev

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.

like image 228
ballaw Avatar asked Feb 08 '12 13:02

ballaw


People also ask

How do I import an existing PyDev project into Eclipse?

If you created the project inside Eclipse, you just have to import the project again (in files > import > general > existing projects into workspace) – it'll look for the existing . project file and will configure it automatically from the existing configuration.

How do I add files to a folder in Eclipse?

Copy & Paste Select the files I want to add in the Explorer/File manager, and copy them (CTRL-C on Windows) Paste them in the project/folder in Eclipse (CTRL-V on Windows)

How do I run code in PyDev?

Go to the menu: Alt + R + S + The number of the Run you wish (It can be Python, Jython, unit-test, etc). Note: if you were using unit-tests, you could use: Ctrl+F9 to run the unit-tests from the module (and even selecting which tests should be run -- and if Shift is pressed it's launched in debug mode).


2 Answers

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.

like image 161
Furbeenator Avatar answered Sep 20 '22 15:09

Furbeenator


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).

like image 30
Tomasz Gandor Avatar answered Sep 22 '22 15:09

Tomasz Gandor