Forums

ImportError: No module named main_flask_app_file

Hi there When I run my flask web app I got this error:

"Error running WSGI application ImportError: No module named main_flask_app_file File "/var/www/mylash_pythonanywhere_com_wsgi.py", line 118, in <module> from main_flask_app_file import app as application"

I deleted my app and create a new one but I also got the same error! Please help and advice what to do to get around this problem - Thank you.

No answer - Could you help me with my question above please!!!

This help page explains how to debug that kind of error. Give it a look, and if you're still having problems after you've gone through the steps there, let us know.

I already went through this page and it didn't help. could you please check the flask app in my account from your end to see if there is a missing file? Thanks.

I am still waiting for your response!!!

In your WSGI file you have this code:

path = "/home/mylash/mysite"
if path not in sys.path:
    sys.path.append(path)

# ...
from main_flask_app_file import app as application

As the help page I linked to earlier explained, this will try to load your Flask app from a file called /home/mylash/mysite/main_flask_app_file.py

Does a file with that name exist? If so, can I look at your files? We can see them from our admin interface, but we always ask for permission first.

I also checked for this file (main_flask_app_file.py) but didn't find it! Please you have my permission to fix this problem from your end.

Thank you.

I'm a bit confused. You've written a WSGI file that says "run the Flask app in this file". Now you need to write that file. Alternatively, if your Flask app is in a different file, then you need to change the WSGI file to point to that file instead.

Sorry, I don't understand you. Could you explain more? my flask app is in /home/mylash/mysite/flask_app.py.

Just to mention that I use manual configuration. I created virtualenv and download flask in my virtualenv. Does that makes problem. Please help!

Thank you.

If your Flask app is in a file called flask_app.py, then you need to specify that in the WSGI file. Replace this line:

from main_flask_app_file import app as application

...with this:

from flask_app import app as application

It works. You're great - many thanks.

Excellent -- glad I could help!

Hello. I have replaced the : from main_flask_app_file import app as application to the name of my original flask app. Yet the error persists. Please help me out

Have you reloaded the web app after the change?