In python I have a folder with three files
- __init__.py
- module.py
- test_module.py
in which the module module.py
is imported inside the file test_module.py
as follows:
from . import module
Of course, when I just run test_module.py
I get an error
> python test_module.py
Traceback (most recent call last):
File "test_module.py", line 4, in <module>
from . import module
ImportError: attempted relative import with no known parent package
But as I set the PYTHONPATH
to the absolute path to where I am working in
export PYTHONPATH=`pwd`
I expect the import to work (as I did set the PYTHONPATH
). But to my surprise I get the same error!
So can I fix the relative import error without any code change?