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

Python环境安装django-heroku时出现异常错误问题求助

Heroku Django构建失败(缺失django-heroku依赖)问题解决方案

核心问题原因

原django-heroku包已官方停止维护,PyPI上现存的0.0.0版本为无效占位版本,安装及调用都会报错。

修复步骤

  • 先确认已激活项目对应的Python虚拟环境,避免依赖安装到全局环境,导致后续导出的requirements.txt缺失必要依赖。
  • 卸载本地无效的django-heroku包:
pip uninstall django-heroku -y
  • 安装官方维护的替代包django-on-heroku:
pip install django-on-heroku
  • 修改项目settings.py配置:
    把原有引入django-heroku的代码:
    import django_heroku
    django_heroku.settings(locals())
    
    替换为:
    import django_on_heroku
    django_on_heroku.settings(locals())
    
  • 更新项目依赖清单:
    执行命令导出最新依赖到requirements.txt,确保Heroku构建时能拉到正确的依赖:
    pip freeze > requirements.txt
    
    导出后手动检查requirements.txt文件,确认已删除django-heroku==0.0.0条目,存在django-on-heroku相关条目。
  • 重新推送代码到Heroku:
    git add .
    git commit -m "fix: replace deprecated django-heroku with django-on-heroku"
    git push heroku main
    

额外说明

Heroku本身支持通过whitenoise中间件托管静态文件,无需额外接入第三方存储即可正常运行,若后续有需要可以直接配置whitenoise简化部署链路。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 06:45:07