You need to enable JavaScript to run this app. Django开发的站点部署到AWS执行eb deploy出现Python版本相关报错
优惠活动
大模型
产品
解决方案
定价
更多

Django开发的站点部署到AWS执行eb deploy出现Python版本相关报错

问题根因
  • 你的Elastic Beanstalk运行环境使用了已停止维护的Python 2.6版本,和本地开发用的Python 3.9.5版本不兼容,导致依赖安装时调用了Python 2.6的pip环境触发报错
  • 配置文件里的container_commands安装的是Python 2对应的依赖包,python-setuptools、python-devel在Amazon Linux默认源里对应Python 2版本,easy_install默认也指向Python 2的工具
修复步骤
  1. 匹配Elastic Beanstalk环境的Python版本

必须选择和本地Python 3.9.5匹配的运行时版本,操作路径:在Elastic Beanstalk控制台进入对应环境→配置→软件→修改,选择Python 3.9作为运行时版本;如果是新建环境,执行eb init时指定Python版本:
eb init -p python-3.9 your-app-name

  1. 修改配置文件的container_commands部分,替换为Python 3对应的包名和工具:
option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: ebdjango.wsgi:application
    PythonVersion: 3.9 # 显式指定Python版本

container_commands:
  01_postgresql:
    command: sudo yum -y install gcc python3-setuptools python3-devel postgresql-devel
  02_postgresql:
    command: sudo pip3 install psycopg2-binary # 优先用预编译的binary包避免编译依赖问题
  1. 重新生成本地requirements.txt,确保所有依赖都适配Python 3.9:
    pip freeze > requirements.txt

  2. 重新执行部署命令:
    eb deploy

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.13 16:30:01