suppose I have a folder structure that looks like this:
.
├── A
│ ├── a.py
│ └── b.py
└── main.py
The files have the following content:
b.py:
class BClass:
pass
a.py:
from b import BClass
main.py:
from A import a
If I run python3.3 A/a.py or python3.3 B/b.by, there are no errors. However, if I run python3.3 main.py, the following error occurs:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from A import a
File "/tmp/python_imports/A/a.py", line 1, in <module>
from b import BClass
ImportError: No module named 'b'
Changing the import-line in a.py to import A.b works, but obviously python3.3 A/a.py will fail then. I am not actually interested in running python3.3 A/a.py but I want the module to be importable from multiple locations. Therefore a.py should import b.py regardless of where a.py is imported.
How can this issue be resolved?
__init__.pyin theAdirectory? - Alfeb.pyreally importing from itself (from b ...) or is that a typo? - Alfe__init__.py, but it does not make a difference. - Max Beikirch