Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing from another project in pydev

Tags:

pydev

I've been looking around for quite some time but I just can't find the answer. Similar questions relate to some tricky cases with third party libraries and all, but my situation seems to be textbook-simple. Nevertheless I can't figure out how this works.

I'm using Eclipse 3.5.2, Pydev 2.2.0, running on an Ubuntu 11.04 machine.

My case seems simple: I want to write a package as its own project, and then I want to write an application using this package in another project.

How should I setup pydev so that I can have this two projects "core" (the package) and "app" (which uses the core package), and from within "app" do:

import core

?

  • I have added core to the Project References of app but it doesn't do anything.
  • I have added /core/ to the Source folders (I had to force for that because is was not showing in the list), it didn't work (so I removed it).
  • I have added /full/path/to/core to the External Libraries, it still doesn't work.

By "doesn't work", I mean that I get an "unresolved import: core", always.

Ideas?

like image 946
Niriel Avatar asked Feb 02 '23 12:02

Niriel


1 Answers

Provided you have 2 projects with the PYTHONPATH properly set (through source folders), it should work just adding a project reference.

Maybe an example can help...

E.g.:

project1
project1/src <-- this should be set as the source folder
project1/src/core
project1/src/core/__init__.py

project2
project2/src <-- this should be set as the source folder
project2/src/app
project2/src/app/__init__.py

and then edit the project2 properties > project references and select 'project1' to be able to access the project1 from the project2.

like image 152
Fabio Zadrozny Avatar answered May 08 '23 12:05

Fabio Zadrozny