简体   繁体   中英

ModuleNotFoundError: No module named 'app' How to fix it?

The structure of my project is:

directories

From test.py I am trying to import models using from app.models import User , but I am getting an error indicating the app module wasn't found. Also, tried from.models import User

Anyone can help me understand what I am missing?

You are most likely in the incorrect working directory. You can check your current directory using.

import os
os.getcwd()

I assume you are in the 'tests' directory, and therefore need to go back one. If so, you can try:

import os
os.chdir('..')
from app.models import User

Try this snippet

from ..models import User 

Could you please try to set FLASK_APP variable and try.

export FLASK_APP=<path_to-run.py>

For power shell:

set FLASK_APP=<path_to-run.py>
$env:FLASK_APP = "<path_to-run.py>"

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