My package tree is as follows:-
My_package
|
+--__init__.py (empty)
+--mainfile.py
+--main_modules
|
+--__init__.py (empty)
+--module1.py
+--module2.py
The content of module2:-
class Wish:
def greatings(self):
print("Hello World!")
wish = Wish()
When I try to import wish from module2 in module1 as:- Content of module1:-
from module2 import wish
There is no error.
But when I import both modules in mainfile.py, Content of mainfile.py:-
from main_modules import module1
from main_modules import module2
An error occurs:-
Traceback (most recent call last):
File "c:\Users\amuly\AppData\Local\Programs\Python\PyProgs\Test package\main package\mainfile.py", line 1, in <module>
from main_modules import module1
File "c:\Users\amuly\AppData\Local\Programs\Python\PyProgs\Test package\main package\main_modules\module1.py", line 1, in <module>
from module2 import wish
ModuleNotFoundError: No module named 'module2'
This is the screenshot of the issue:- Screen Shot
I have searched various related questions and tried all to my best but it is not working