在Heroku上安装django-tables2时出错:无效命令‘egg_info’
First, let's recap the error you ran into (formatted for clarity):
~ $ pip install django-tables21.21.1
Collecting django-tables21.21.1
Using cached django-tables2-1.21.1.tar.gz
Complete output from command python setup.py egg_info:
/app/.heroku/python/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'extras_require'
warnings.warn(msg)
/app/.heroku/python/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option...
What's causing this?
The root issues are tied to Python version compatibility:
- django-tables2 1.21.1 drops support for Python 2.7: Starting from version 1.20, django-tables2 only supports Python 3.5 and above. Your Heroku dyno is running Python 2.7, which is completely out of sync with this package version.
- Outdated tooling warning: The
extras_requirewarning pops up because your Python 2.7 environment uses the old, unmaintaineddistutilsinstead ofsetuptools(which adds support for that option). But this is just a side effect of using an outdated Python version.
How to fix it
You've got two solid options:
Option 1: Downgrade django-tables2 to a Python 2.7-compatible version
If you absolutely need to stick with Python 2.7 for now, install the last version of django-tables2 that supports it:
pip install django-tables2==1.11.2
This is the final stable release that works with Python 2.7, so it should install without those warnings.
Option 2: Upgrade your Heroku app to Python 3.x (highly recommended)
Python 2.7 has been end-of-life since 2020—no security updates, no new package support. It's worth making the switch:
- Create or edit a
runtime.txtfile in your project root to specify a supported Python 3 version (e.g.,):
python-3.8.18
(Heroku supports several 3.x versions; 3.7+ will work with django-tables2 1.21.1)
2. Update your requirements.txt to ensure all your dependencies (like Django) are compatible with Python 3.
3. Deploy the changes:
git add runtime.txt requirements.txt git commit -m "Upgrade to Python 3.8 and update dependencies" git push heroku main
Once deployed, running pip install django-tables2==1.21.1 will work as expected.
内容的提问来源于stack exchange,提问作者James Dernie

