ModuleNotFoundError: No module named 'Directory_one'

Hi All,

I am trying to access method from another module in one of my file but I keep getting ModuleNotFoundError.

This how my folder structure is:

Appreciate for your help

Thanks
Lax

Can any one help me here?

Modules and packages that are imported can only be imported from the search path. See:

The module Directory_one is not on sys.path you run the tests. It is not in

  • The directory containing the input script (i.e. Directory_two).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH ).
  • The installation-dependent default (where the standard library and modules/packages installed with pip are).

In this case you probably best reorganize your directories into a package, so you can reference the modules among themselves directly. This is however dependent on what more you are going to add.

DEMO <== becomes the package
    __init__.py
    Directory_one
         myclass.py
    Directory_two
          mytest.py

Now from mytest.py you can reference things in myclass via import Directory_one.myclass. Make sure your working directory is one level above DEMO.

1 Like