I have folder structure as below
mypackage/
__init__.py
package1/
__init__.py
module1.py # has ClassOne
module2.py # has ClassTwo
script.py
package2/
__init__.py
module3.py # has ClassThree
module4.py # has ClassFour
In script.py
I want to access ClassFour from module4
so I am using relative imports like below
from ..module4 import ClassFour
c = ClassFour()
but I am getting en error
ValueError: attempted relative import beyond top-level package
I know I can solve this using
import sys
sys.path.append("path/to/my/module/")
But I am interested in solution with relative imports.
I referred few questions and tried the solutions like - How to do relative imports
And also tried to run my file using
python -m script
but no success