I am getting an error in my project where I cannot import my code. I am not sure why this is happening, as I've never run into this issue before.
I have consulted these questions:
ModuleNotFoundError: What does it mean main is not a package?
ModuleNotFoundError: No module named 'main.xxxx'; 'main' is not a package
No module named 'main.demo'; 'main' is not a package python3
My project's setup looks like this:
-code
-__init__.py
-my_module.py
-driver.py
-tests
-__init__.py
-test_my_module.py
When trying to execute the following code:
from .my_module import MyModule
if __name__ == '__main__':
my_mod = MyModule()
I get the following error:
Traceback (most recent call last):
File "driver.py", line 1, in <module>
from .my_module import MyModule
ModuleNotFoundError: No module named '__main__.my_module'; '__main__' is not a package
I am running this when in the code directory. I have tried the following imports as well:
from code.my_module import MyModule
from ..my_module import MyModule
import my_module.MyModule
import MyModule
Any help is greatly appreciated.