Search code examples
pythonpython-importmodulenotfounderror

ModuleNotFoundError: No module named - Python


Can someone please help with this error? I have tried all sort of ways to import a module in Python but not has worked so far. I have this directory structure below:

|__folder1:
|      |__folder1a
|          |___inner_file.py
|__outer_file.py

I want to import a Class from the outer_file.py into the inner_file.py. However, I have been getting the error ModuleNotFoundError: No module named.

I have tried all the options in this link on GeeksforGeeks. Thanks.


Solution

  • easy

    import sys,os
    BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.insert(0, BASE)
    

    enter image description here