I have the following directory structure on a project that has been inherited:
work_dir/
FlaskControlPanel/
static/
templates/
app.py
models/
__init__.py
model1.py
model2.py
script1.py
script2.py
From script1.py
or script2.py
I can run this from models.model1 import Class1, Class2
and it works. When using PyCharm, I can use the same import line within app.py
.
However, when I go to deploy this on my dev server, this doesn't work from app.py
. I get the error ImportError: No module named models.model1
What does PyCharm do to get around this?
How can I fix my import in app.py
to work in both PyCharm and when I run my Flask application on the development server? I usually run it on the server just using python app.py
from within the FlaskControlPanel
directory.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…