Heroku部署Flask项目报错:gunicorn无法识别参数app:app
Got it, let's work through this Gunicorn error you're hitting on Heroku. I've dealt with this exact issue a few times, so here are the most common fixes to try:
Double-check your Flask app entry details
First, confirm two key things:- Is your main Flask file named
app.py? If your entry file is something else (likemain.pyorwsgi.py), you need to update the Procfile to match. For example, if your file ismain.py, the Procfile should beweb: gunicorn main:app. - Does your Flask instance actually have the name
app? Check your code—if you defined it asapplication = Flask(__name__)instead ofapp = Flask(__name__), your Procfile needs to beweb: gunicorn app:application(format isfilename:instance_name).
- Is your main Flask file named
Verify Gunicorn is properly specified in requirements.txt
Heroku relies on yourrequirements.txtto install dependencies. Make sure you've added Gunicorn to this file—add a line likegunicorn==20.1.0(use a stable recent version) to avoid version mismatches. If you only installed it locally but didn't list it here, Heroku might be using an incompatible version that doesn't recognize thefile:instancesyntax.Check your project structure and working directory
If yourapp.pyis inside a subfolder (likesrc/app.py), you need to adjust the Procfile path using dots instead of slashes:web: gunicorn src.app:app. Also, test the command locally first—rungunicorn app:appfrom your project root. If it fails locally, fix that before redeploying to Heroku.Ensure your Procfile is formatted correctly
Small typos here can cause big issues:- The file must be named exactly
Procfile(capital P, no .txt extension) - It needs to live in your project's root directory, not a subfolder
- No extra spaces or line breaks in the line
web: gunicorn app:app
- The file must be named exactly
Test each of these steps one by one, and you should get past that error.
内容的提问来源于stack exchange,提问作者Engramar Bollas

