Git Push至Heroku Master失败:requirements.txt文件依赖安装报错
First, let's tackle the immediate error stopping your deployment:
ERROR: Could not find a version that satisfies the requirement anaconda-project0.9.1 (from -r /tmp/build_da51543d/requirements.txt (line 3)) (from versions: none)
ERROR: No matching distribution found for anaconda-project0.9.1
Why this is happening
You're hitting two key issues:
anaconda-projectisn't hosted on PyPI: This package is exclusive to the Anaconda ecosystem—Heroku usespipto install dependencies, which can only pull packages from the standard Python Package Index. It has no access to Anaconda's private repositories.- Your
requirements.txtis full of unnecessary bloat: You exported every package from your local Anaconda environment, including dozens of Anaconda-specific tools (likeconda,spyder,anaconda-navigator) that your app doesn't need to run. These extra packages not only slow down deployment but also cause conflicts and missing package errors.
Step 1: Generate a clean, minimal requirements.txt
The best fix is to create a stripped-down list of only the packages your application actually depends on. Here's how:
- Create a fresh virtual environment (use either Python's built-in
venvor a new conda environment):# Using venv (recommended for Heroku) python -m venv app-env source app-env/bin/activate # For Windows: app-env\Scripts\activate # Or using conda conda create --name app-env python=3.x conda activate app-env - Install only the packages your app needs (example for a Django + TensorFlow app):
pip install django tensorflow opencv-python gunicorn pillow ... - Generate a clean requirements file:
pip freeze > requirements.txt
Step 2: Quick patch for your existing file (if you don't want to rebuild the env)
If you want to fix your current requirements.txt immediately, manually delete all Anaconda-specific and development-only packages. These include:
anaconda-client,anaconda-navigator,anaconda-projectconda,conda-build,conda-package-handling,conda-verifyspyder,spyder-kernels,navigator-updater- Linting/development tools like
pylint,autopep8,flake8(unless your app requires them to run)
Step 3: Resolve the earlier absl-py error
The previous missing directory error for absl-py was almost certainly a temporary Heroku build cache glitch. With a clean requirements.txt, Heroku will pull the correct wheel for absl-py==0.11.0 directly from PyPI, no path issues included.
Final Deployment
After updating your requirements.txt, commit the changes and push again:
git add requirements.txt git commit -m "Trim requirements.txt to only app dependencies" git push heroku master
内容的提问来源于stack exchange,提问作者saucypanda

