1

I have co'd existing code from an SVN repo that uses full imports - by which I mean:

-->projectdir

-------->dira

-------------->a1.py

-------------->a2.py

-------->dirb

-------------->b1.py

Suppose a1.py imports a method from a2.py:

Normally I would simply write:

from a2 import xyz

Here they have written it as:

from project_dir.dira.a2 import xyz

How do I make eclipse recogonize these imports?

Basically I want to be able to Ctrl+click and Open Declaration. I need to browse through this massive project and I simply cannot do so until this works.

PS:

  1. I have tried adding the projectdir to the PYTHONPATH
  2. I have tried adding each and every sub-directory to PYTHONPATH
  3. I have an init in every folder -_-
rtindru
  • 5,107
  • 9
  • 41
  • 59
  • The project directori names are not the same: project_dir vs projectdir. You also have an extra directory e.g. `from project_dir.a2 import xyz` is missing any refernece to `dira`. If you can link to the SVN repo/project in question it will help. – Tom Dalton Aug 01 '14 at 11:15
  • @TomDalton Okay the project_dir and projectdir was a type. They're the same. – rtindru Aug 01 '14 at 11:19
  • `from project_dir.dira.a2 import xyz` suggests that the directory containing `project_dir` is in their pythonpath. If you need to add that to eclipse then your probably best off making an extra directory above project_dir for your eclipse project. E.g. `eclipse_project/project_dir/dira/...`. You can then add the root of the eclipse project to the (eclipse) pythonpath and it should work. – Tom Dalton Aug 01 '14 at 11:28
  • The answer here works: http://stackoverflow.com/questions/4631377/unresolved-import-issues-with-pydev-and-eclipse?rq=1 – rtindru Aug 12 '14 at 04:58

1 Answers1

1

For that to work you need to have init.py under 'project_dir', 'dira' and 'dirb' and then you need to set as a source folder the directory which is the parent of the 'project_dir' (and not the project_dir itself) -- and no other directories should be set as source folders.

I.e.: the source folder is the directory added to the PYTHONPATH (so, for importing 'project_dir', its parent must be in the PYTHONPATH).

Note: You may have to remove the project from Eclipse/PyDev and recreate it a level before for this to work depending on how you created it the first time.

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78