I always struggled with Python package import. I searched the web, but wasn't able to find an appropriate answer.
I have the following directory structure:
.
./__init__.py
./packages/
./packages/__init__.py
./packages/package
./packages/package/__init__.py
./packages/package/module.py
The module.py source contains only one line:
import package
If I go to "packages" directory, I am able to import package:
>>> import python
>>>
If I go to "." directory, I would like to import the module (or the package) as follow:
>>> import packages.package.module as module
but i'm getting the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "vendor/package/module.py", line 1, in <module>
import package
ImportError: No module named package
What do I need to put in the __init__.py files, so I can do the above import?
More, what do I need to put in ./__init__.py file, so I will able to import my project from ../ directory?
If possible, I would like to solve this problem without changing the sys.path variable.