Python,Function Runtimes must have a valid version

My app.py is just a simple Python program, vercel console node version I set to 18x, and then my vercel.json configuration is as follows, when I deploy, prompt picture error. How do I solve it?

my vercel.json

{
	"version": 2,
    "functions": {
        "app.py": {
            "runtime": "vercel-python@3.9" , // or vercel-python@3.12
            "maxDuration": 30,
            "memory": 1024
        }
    },
    "routes": [
        {
            "src": "/(.*)",
            "dest": "/app.py"
        }
    ]
}

Hi, @lijunyi2!

Welcome to the Vercel Community :smiley:

I don’t see any issues with your vercel.json file. Do you have any other configuration files e.g. requirements.txt?

Some things I would try:

  • Removing the runtime on your .json all together. You don’t necessarily need to specify the version as by default, new projects will use the latest Python version available on Vercel.

  • Specifying the version in a Pipfile. From the relevant documentation:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
 
[packages]
flask = "*"
 
[requires]
python_version = "3.12"

I’ll also leave some examples of some Python projects that might be helpful to look at.

My requirements.txt content is as follows:

Flask==3.0.3
Flask-Cors==3.0.10
gunicorn==20.1.0

my app.py content is as follows:

from flask import Flask, request, jsonify
from flask_cors import CORS
import poplib
from email.parser import BytesParser
import re
import time

app = Flask(__name__)
CORS(app)


@app.route('/', methods=['POST'])
def home():
    return jsonify({"msg": "test",
                    "data": "test"}), 200

The structure of my project is as follows:

So how can I modify my configuration to solve this deployment problem?

I solved it myself, thank you.

Great to hear, @lijunyi2! Could you share your solution?

The file directory is like this:
image

the vercel.json is like this:

{
  "rewrites": [
    { "source": "/(.*)", "destination": "/api/index" }
  ],
  "functions": {
    "api/*.py": {
      "maxDuration": 60
    }
  }
}

/api/index, index is your file name。

I solved the python project, but the nodejs project is different from this. Do you have an example of how to set maxDuration in nodejs?