Search code examples
pythonmodulenotfounderror

ModuleNotFoundError: No module named 'app.lang'; 'app' is not a package


I have this file structure in my python project

|__src 
   |__main.py
   |__gen.py  
     |__app     
        |__ __init__.py
        |__ app.py
        |__ lang.py

Intention

I want to use the Language class from sibling module lang. So I tried with this import statement in app.py:

from app.lang import Language

Issue

But when I run app.py I get a ModuleNotFoundError error saying 'app' is not a package:

enter image description here

Which doesn't make sense since app has __init__.py.

How can I solve this?


Solution

  • Because both app.py and lang.py are in the same directory try to import like this :

    from .lang import Language
    

    or you can use from app.lang import Language from another file located outside app folder