My project structure looks like this
pythonProject
|
|-__init__.py
|
|- a
| |- file_a.py
| |-__init__.py
|
|- b
|- file_b.py
|-__init__.py
I've also attached the image of my project's structure below.
My file_a.py
looks like:
class class_a:
def __init__(self):
pass
def show(self):
print('class A')
if __name__ == "__main__":
pass
My file_b.py
looks like:
from pythonProject.a.file_a import class_a
class class_b:
def __init__(self):
pass
def show(self):
a = class_a()
a.show()
if __name__ == "__main__":
b = class_b()
But I keep getting an error No module named 'pythonProject'
. All the folders do have __init__.py
file. What am I doing wrong?
On the terminal, I run the command python b/file_b.py
from inside the pythonProject.
Also, I would not like to add project path using sys library.
Thanks.
Things I've tried.
- I added all the
__init__.py
file in all the folders. But all of them are empty. Should they have any specific references? - I tried the import line to
..a.file_a import class_a
. Then I get the error:ImportError: attempted relative import with no known parent package
- I tried the import line to
a.file_a import class_a
but then the error isModuleNotFoundError: No module named 'a'
.