Problem Setting Up Flask App

I'm having difficulty following the tutorial video setting up the Flask App. The issue comes in when I give this command after installing Gunicorn:

gunicorn -w 3 flask_project:app

I get this error message:

from flask import Flask, jsonify
ImportError: No module named flask

I have installed Flask. I followed the tutorial precisely and it's not working.

Thanks!

1 Reply

I haven't worked with Flask before, though I have had some limited experience with Python-related frameworks. What I've found working with Python is that error messages, like the one you posted, don't tell me the cause of the error, just that something didn't work.

I would re-review the tutorial that you followed. There could always be a chance that something got updated or there's an error with the guide. Did you run this on the right version of Python? Were there any prerequisites that were overlooked?

You can get more helpful errors from your Linode's logs. For Gunicorn, you can run:

sudo journalctl -u gunicorn

I also found this post that provides a number of helpful answers, the top voted one being to recreate your virtualenv that you're running this in:

Flask ImportError: No Module Named Flask

We have a How to deploy a Flask Application on Ubuntu guide. If you followed that one, are you running the command from the root directory of the project? Here's what step 2 states:

Run Gunicorn from the root directory of the application, flask_app_project. The command tells Gunicorn to look for the WSGI instance named app in the flask_app directory. In the example project, the WSGI instance named app is located in /home/Flask-on-Linode/flask_app/__init__.py.

This post helps to walk you through compiling your WSGI, which may be an issue if you're encountering an issue here:
500 internal server error mod_wsgi apache "importerror: No Module named 'django'
This isn't as likely, though I came across it in my research and felt it's helpful enough to include it here in case someone else comes across your post with a different reason for the error.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct