How can I import python files correctly?

  import, importerror, python

I have a folder that contains two other folders inside, like this:

training:
        |-- part1:
                 |-- __init__.py
                 |-- a.py

        |-- part2:
                 |-- __init.py
                 |-- b.py

when I want to import b.py in a.py, I get error. I’ve test two ways and get error in both of them explained here:

way1:

from training.part2.b import b

error:

Exception has occurred: ModuleNotFoundError
No module named 'training' 

way2:

from ..part2.b import b

error:

Exception has occurred: ImportError
attempted relative import with no known parent package

can anyone help me to solve this problem? I will be very gratefull.

Source: Python Questions

LEAVE A COMMENT