Import error in Eclipse when importing packages with the same name

I have a pydev project open in eclipse.

The nested package packages are as follows:

my-package: my-sub-package: foo 

In this project, I am using import from another project that I created. Another project nesting:

 my-package: my-sub-package: bar 

Thus, the 2 main packages have the same name.

When trying to import: from my-package.my-sub-package import bar I get ImportError: No module named bar .

I assume that this is because eclipse is searching in the current project and when it does not find the bar , it does not look for it in dist-utils (where I pip installed the project I'm trying to import from).

(When trying to do the same import from regular python opened from the same place, the import works fine, so this is something in eclipse).

Is there a way to tell eclipse to continue searching for a module in all folders in pythonpath (so that it can reach dist-utils) even if the packages have the same name and it did not find the right package in the current project?

Thank you very much.

+4
source share
1 answer

Where do you control a regular python? if you have

 src-root: my-package: __init__.py my-sub-package: __init__.py foo.py 

and you start regular python from src-root, then you will get the same result that it will not work, but if you run it somewhere else, it will probably work as you say.

If you cannot rename any of the packages, the only thing you need to remove is the current scripted root from the "Source folder" in your eclipse PyDev options, but that does not mean that you will never access foo my-package again. See http://docs.python.org/2/library/sys.html#sys.path

0
source

All Articles