You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flask应用部署Heroku遇问题:无法兼容Python Buildpack

Fixing Heroku Python Buildpack Detection Failure

Here are actionable steps to resolve the "App not compatible with buildpack" error:

1. Verify Procfile Correctness

  • Ensure the Procfile is in the root directory of your git repo, has no file extension, and uses the exact name Procfile (uppercase 'P').
  • Check that its content follows the proper format for Flask apps:
    web: gunicorn <your-flask-module>:<flask-app-instance>
    
    Replace <your-flask-module> with the name of your main Flask file (e.g., app if your file is app.py) and <flask-app-instance> with the name of your Flask object (e.g., app if you have app = Flask(__name__)).

2. Confirm Files Are Tracked in Git

Even if files exist locally, they won’t be sent to Heroku unless committed to git:

  • Run git status to check if Procfile and requirements.txt are listed under "Changes to be committed" or "Untracked files".
  • If untracked, add them with:
    git add Procfile requirements.txt
    git commit -m "Add Procfile and requirements.txt"
    
  • Push again with git push heroku main.

3. Specify Python Version Explicitly

Heroku may default to an older Python version if not specified. Add a runtime.txt file to your root directory with:

python-3.12.1

Commit this file and push to Heroku. This ensures Heroku uses the same Python version as your local environment.

4. Clean Up requirements.txt

Your requirements.txt includes platform-specific packages (like pywin32, pywinpty) that are incompatible with Heroku’s Linux environment. Remove these entries, then test installing dependencies locally with:

pip install -r requirements.txt

Fix any installation errors before pushing to Heroku.

5. Check Repository Structure

Ensure your git repository root contains all necessary files (Procfile, requirements.txt, main Flask app files). Avoid nesting your app in a subdirectory—Heroku expects core files at the root for proper buildpack detection.

6. Reset Buildpacks

Manually resetting the buildpack can resolve detection glitches:

heroku buildpacks:clear
heroku buildpacks:set heroku/python
git push heroku main

If the issue persists, run heroku logs --tail to pull full build logs for more detailed error clues.

内容的提问来源于stack exchange,提问作者pyguypy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:05:58