Heroku部署报错:应用与Python Buildpack不兼容,含requirements.txt求帮助
Hey there, let's work through this Heroku build issue together! Even though you’ve included a requirements.txt file, there are a handful of common snags that might be causing the buildpack detection to fail. Here’s what to check:
Confirm
requirements.txtis in the root directory
Heroku’s Python buildpack only looks for this file directly in your project’s root folder, not in subdirectories. Double-check withls(Mac/Linux) ordir(Windows) in your local project root to make sure it’s placed correctly.Validate the file’s content
An empty or malformedrequirements.txtcan trigger a detection failure. Open the file and ensure it has at least one valid Python package dependency (e.g.,requests>=2.25.1). Watch out for typos in package names, duplicate entries, or odd encoding issues that might throw off the buildpack.Ensure the file is tracked by git
Ifrequirements.txtisn’t committed to git, Heroku won’t see it when you push. Rungit statusto check its status—if it’s untracked, run these commands:git add requirements.txt git commit -m "Add requirements.txt to track dependencies"Then try pushing to Heroku again.
Manually set the Python buildpack
Sometimes Heroku’s auto-detection misses the mark. Force the Python buildpack with this command:heroku buildpacks:set heroku/pythonAfter setting it, push your code again with
git push heroku main(replacemainwith your branch name if needed).Check for conflicting buildpacks
If you’ve previously added other buildpacks, they might interfere. Runheroku buildpacksto list active buildpacks—make sure onlyheroku/pythonis present. Remove any extra ones with:heroku buildpacks:remove <buildpack-name>
Give these steps a try in order, and your app should deploy successfully soon!
内容的提问来源于stack exchange,提问作者coder

