Can't start my import statements with the top-level module (the source
folder)
I seem to be running into this issue intermittently.
Sometimes I have a PyDev project in which I get compile errors if I try to
start my imports with the name of the top-level folder. So, suppose my
project looks like this:
+ myproject
- __init__.py
- a.py
- b.py
+ package1
- c.py
- __init__.py
+ package2
- d.py
- e.py
- __init__.py
If I'm in file a.py, it won't let me do imports like this, for example:
from myproject.b import foo
import myproject.b
The same goes for any file. They all compile just fine if I leave off
"myproject" from the imports statement like this:
from b import foo
import b
Just like in the diagram, I definitely have a top-level __init__.py, and
both the myproject folder and its parent are on the Python path. The
myproject folder is also the source folder for the project.
I need the complete import statement because places I'm deploying this
code to won't have the myproject folder on their path. Some other projects
that seem to be configured the same way don't have this problem, and I've
tried the usual cleaning/restarting.
Any idea as to what's going on here?
Thanks!
No comments:
Post a Comment