Linking Python projects in Eclipse with PyDev

This is deprecated:  it still works, but see my later post about referencing Eclipse PyDev projects.

Suppose you have two Python projects in the Eclipse IDE and you are using the PyDev plugin for Eclipse.  You want to import one project from another.

One way to do it:

  1. in first project, in Eclipse, created a linked folder to the source subfolder of the second project, containing a module named foo.
  2. in the first project, in Eclipse, add the linked folder to Properties> PyDev PYTHON_PATH> Source folders
  3. in the first project, in some file, use “from foo import FooClass”

This is what your Eclipse directory tree looks like (in the PyDev Package Explorer frame):

FirstProject 
   > packageFoo  
   packageBar     
       __init__.py
       bar.py
SecondProject  
   packageFoo
     __init__.py
     foo.py

Here, the indentation level shows the tree structure, and the “>” is the icon that Eclipse uses to indicate a linked folder. In bar.py, you find the code:

from foo import FooClass

Note that you import module foo, not packageFoo.foo (since packageFoo is in PYTHON_PATH, its modules can be imported.)

Note that the packages ARE packages because they include a file named __init__.py.  That file typically is empty.

Advertisements

2 thoughts on “Linking Python projects in Eclipse with PyDev

  1. Hi there, actually, I don’t think this should be needed… you can just create 2 independent projects each with its our source folder and if you should import contents from the other, you can go to the project properties > project references and just add a reference (this will make the contents of the referenced project available so that your imports will work properly and the PYTHONPATH at the launch is also correct)..

  2. Thanks, I am unfamiliar with ‘project references’ but I will try it. It might cure some of the problems I have been having with relative imports?

    Thanks also for PyDev. Is there an appropriate place to ask for new features? I wish for a “Show all members” feature, such as you find in the Qt documentation, or “Short versus long outline” such as you find in Eiffel IDE. For a class, it would should all members, even those inherited.

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