-2

Im trying to import functions from others files in other directory, but take error ModuleNotFoundError

Test structure:

py_path/
    p1/
        __init__.py
        s1.py
    p2/
        __init__.py
        s2.py
    __init__.py

py_path/__init__.py:

from . import p1, p2

py_path/p1/__init__.py:

from s1 import *

py_path/p1/s1.py:

from .p2 import s2
f2()

py_path/p2/__init__.py:

from s2 import *

py_path/p2/s2.py:

def f2():
    print('test func in s2.py')

How import module from other file?

1 Answers1

-1

I think you can import path from the sys module and add the address of the file you want to use to it. This way you can import module from other files. I hope that it's useful for you :).

0nE
  • 1
  • 3