I tried different methods shown on multiple sites but couldnt figure out the problem. I need to import "demo1.py" in "demo2.py". Here is my folder hierarchy:
Project:___ __init__.py
|_ main.py
|_ Package1:___ __init__.py
| |_ demo1.py
|_ Package2:___ __init__.py
|_ demo2.py
When I have this in main.py, it works.
import Package1.demo1
import Package2.demo2
But this doesnt work in demo2.py
import Package1.demo1
Neither does this:
import Project.Package1.demo1
I tried following this tutorial https://www.programiz.com/python-programming/package but Im doing something wrong. Tried renaming "main.py" to something else in case it is causing problems but that doesnt helped either.
Edit: Solution found
from sys import path
import os
par_dir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.pardir))
path.append(par_dir)
import Package1.demo