Reputation: 63259
Some authoritative names have commented and/or answered about the general problem of relative imports
when trying to run a script within the module directory here: Relative imports in Python 3
My issue is that the Pycharm
IDE is parsing the module and running it in this same directory. So I end up with import errors. Note that there is an __init__.py
in the package. Looks fine to pycharm
parser
from . logger import * # Logger is a module in same package
But ..
Traceback (most recent call last):
File "/git/bluej/fusion/python/pointr/bluej/util/DB.py", line 6, in <module>
from . logger import *
ImportError: attempted relative import with no known parent package
the Run Configuration
was created by right-clicking in the module. The auto generated version is like this: having the working directory
the same as the script dir. /git/bluej/fusion/python/pointr/bluej/util
(note the package is pointr.blue.util
):
I tried out putting the Working Directory
at the base python
directory level: /git/bluej/fusion/python/
However that did not have any effect.
Responding to a comment: logger
is not the root package and so the following code does not work:
How can I develop, debug, and run modules with relative imports in Pycharm
?
Upvotes: 6
Views: 2268
Reputation: 63259
Configuration
Upvotes: 7