简体   繁体   中英

Import Error - Pydev Eclipse

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:

Here they have written it as:

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 -_-

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.

Ie: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM