简体   繁体   中英

Python folder structure - ModuleNotFoundError

I got the error:

 File ".\main.py", line 3, in <module>
from app.core import config
ModuleNotFoundError: No module named 'app'

in the line 3 of main.py:

from app.core import config

I have tried the left empty the file app/ init .py and with the next:

from .core import config

My structure folder is:

backend
│
└───app
    │   .env
    │   main.py
    │   __init__.py
    │
    ├───api
    │       __init__.py
    │
    ├───core
    │       config.py
    │       __init__.py
    │
    ├───db
    │       base.py
    │       base_class.py
    │       __init__.py
    │
    ├───db_models
    │       association_tables.py
    │       team.py
    │       user.py
    │       __init__.py
    │
    └───schema
        │   mutation.py
        │   query.py
        │   __init__.py
        │
        ├───team
        │       mutations.py
        │       queries.py
        │       types.py
        │       __init__.py
        │
        └───user
                mutations.py
                queries.py
                types.py
                __init__.py

I'd due to problem with absolute/relative reference. I use PyCharm and I don't have alarm about the reachable or not of the modules.

thanks for advance

I rebuilt your structure and this should do the trick:

from core import config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM