By fabio geraci
Hello, i must say this is my first project. Now I built a flask app, that uses a image classifier. the flask integration works fine locally, but i would like to deploy the app to a lager audience.
i followed the deployment strategy proposed on this git https://github.com/digitalocean/sample-flask.git but i get the following error:
number-reader | 12:12:52 usage: gunicorn [OPTIONS] [APP_MODULE] number-reader | 12:12:52 gunicorn: error: No application module specified.
app = Flask(__name__)
# To setup Bootstrap templates
Bootstrap(app)
# Load trained model
with open("model/classifier.pickle", "rb") as handle:
classifier = pickle.load(handle)
@app.route('/', methods=['GET', 'POST'])
def load_image():
if request.method == 'POST':
if __name__ == '__main__':
app.run(debug=True)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Try something like this in settings->components->your component:
gunicorn --worker-tmp-dir /dev/shm app:app
The first part is something that digitalocean suggests: “”“Gunicorn crashes with PermissionError unless launched with a specific argument due to an issue with Gunicorn running in Docker. To resolve, run Gunicorn to use a different location for its temp files by passing this option to the run command: gunicorn --worker-tmp-dir /dev/shm project.wsgi”“”
But it worked for me changing the project.wsgi for app:app (it is what I use on my local machine for testing, since my app file is called app.py)
The error you’re encountering suggests that Gunicorn, the Python WSGI HTTP Server for UNIX, is not able to find your Flask application object. When you deploy a Flask app using Gunicorn, you need to specify the application object it should serve. This is usually done in the command that starts Gunicorn.
Based on your code snippet, it looks like your Flask app is defined as app in the Python file where your Flask application is located. The way you start Gunicorn must include a reference to this app object, typically in the format module:app. Here, module is the name of the Python file containing your Flask application (without the .py extension), and app is the Flask application object.
Here’s how you can resolve this issue:
Ensure Correct File Structure: Your Flask application should be in a Python file, let’s assume it’s named app.py.
Gunicorn Command: The command to start Gunicorn should reference this file and the Flask app object. If your file is named app.py and your Flask object is app, the command should be:
gunicorn app:app
Make sure this command is used in your deployment process.
Procfile. The Procfile should contain:web: gunicorn app:app
Ensure app.py is Accessible: The app.py file (or whatever your main file is named) should be in the root directory of your project, or the path should be correctly specified in the Gunicorn command.
Check for Typos: Ensure there are no typos in your file names and in your Gunicorn command.
No Conditional app.run(): When deploying with Gunicorn, you don’t need the if __name__ == '__main__': app.run(debug=True) block in your code. Gunicorn acts as the web server, and you won’t be running the app directly with Python.
Adjust for Non-Standard Structures: If your Flask app object is in a different file or is named differently, adjust the Gunicorn command accordingly. For example, if the Flask app object named myapp is in a file named myapplication.py, the command would be gunicorn myapplication:myapp.
After making these adjustments, try redeploying your application. If the problem persists, you may need to check your deployment configuration and ensure all paths and file names are correctly specified.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.