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

在Vercel部署Django应用时遇到Python运行时配置错误

解决Vercel部署Django时的Python Runtime错误

问题场景

部署Django应用到Vercel时触发以下错误:

WARN! Due to builds existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply.
Installing Builder: @ardnt/vercel-python-wsgi
Starting build
Build AMI version: Amazon Linux release 2 (Karoo)
ERROR Invalid runtime configured (python3.6). Available runtimes:
ERROR - python3.9
Error: Invalid runtime configured (python3.6).

当前使用的vercel.json配置:

{
  "builds": [{
    "src": "Portfolio/wsgi.py",
    "use": "@vercel/python",
    "config": { "maxLambdaSize": "15mb", "runtime": "python3.9" }
  }],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "Portfolio/wsgi.py"
    }
  ]
}

wsgi.py内容:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Portfolio.settings')

application = get_wsgi_application()

app = application

问题原因

尽管vercel.json中明确指定了python3.9,但Vercel仍读取到了python3.6的配置,通常是以下原因:

  • 项目根目录存在runtime.txt文件,内容为python3.6
  • Vercel项目环境变量中设置了PYTHON_VERSION=3.6
  • 旧构建缓存残留了过时的配置

解决方案

  1. 检查runtime.txt文件:
    若项目根目录有该文件,将内容改为python-3.9(注意格式为python-<版本号>,而非python3.9);若没有则无需创建。

  2. 清理环境变量:
    进入Vercel项目的「Settings」→「Environment Variables」,查找是否存在PYTHON_VERSION变量,如有则删除或修改为3.9。

  3. 强制清理构建缓存:
    在Vercel部署页面点击「Redeploy」,勾选「Redeploy with clean cache」选项,重新触发构建。

  4. 验证构建依赖:
    确认使用的@ardnt/vercel-python-wsgi构建器版本为最新,避免版本兼容问题导致的配置读取异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 22:33:15