-1
|Project
|--m1Folder
|--|--__init__.py
|--|--m1.py
|--m2Folder
|--|--__init__.py
|--|--m3Folder
|--|--|--__init__.py
|--|--|--m3.py

m1Folder and m2Folder are inside of Project. m3Folder is inside of m2Folder. All m*Folder contains empty __init__.py.

How to import m1.py, from m3.py file?

I tried from m1Folder import m1 as mo inside m3.py file and gave ModuleNotFoundError: No module named 'm1Folder'. However, pylint in vscode did not show any error.

from ...m1Folder import m1 as mo gives ValueError: attempted relative import beyond top-level package

Dr.PB
  • 959
  • 1
  • 13
  • 34

1 Answers1

0

You can do it by changing the system path with the sys module.

import sys
sys.path.insert(1, '/path/to/application/app/folder')
import m1
Aleksander Ikleiw
  • 2,549
  • 1
  • 8
  • 26