I'm still learning to code better in Python. Therefore I am trying to use some constructions in my programming. Things like name_conventions and structured packaging & modules.
That said I come across an issue which I cannot resolve, it seems. The structure I chose is as follows:
- Core
- __init__.py
- controller.py
- Dashboard
- Log
- Plugins
- Stats
- __init__.py
- controller.py
- Plugin2
- Plugin3
- Etc..
- Stats
- main.py
In the Core controller.py i am trying to import the Stats(object) class. I have tried several different ways. In my IDE (Pycharm) it works like a charm ;) When i try to start it via Command Line i get ImportErrors. I have tried different approaches.
from Plugins.Stats.controller import Stats
from Plugins.Stats import controller
from Plugins.Stats import controller.Stats
from Plugins import Stats.controller
I also tried to put the Stats
class into the Plugins.Stats.__init__.py
and call it:
from Plugins.Stats import Stats
and I get this:
Traceback (most recent call last):
File "controller.py", line 4, in <module>
from Plugins.Stats.controller import Stats
ImportError: No module named 'Plugins'
The funny thing is... When i try to do the same from main.py. It does work. So I am really confused. Am I doing something wrong?
Also are there special design patterns to handle imports?