Preparazione dei file di configurazione per il runtime Python 3
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Prima di poter eseguire l'app nel runtime Python 3 dell'ambiente standard di App Engine, potresti dover modificare alcuni dei file di configurazione utilizzati da App Engine:
app.yaml. Questo file contiene informazioni sul codice dell'app, come il runtime e i gestori dell'app.
appengine_config.py. Il runtime di Python 2 utilizza questo file per accedere alle librerie di terze parti e fornire valori per costanti e "funzioni hook".
Il runtime di Python 3 non utilizza questo file.
Aggiornamento di app.yaml in corso…
Il comportamento di alcuni campi nel
app.yaml file di configurazione
è stato modificato. Rimuovi i campi non più supportati e aggiorna gli altri campi come descritto nella tabella seguente.
Si presume che tutte le applicazioni siano a prova di thread. Se la tua applicazione non è sicura per i thread, specifica un entrypoint che configuri un thread per worker.
Ad esempio, quando utilizzi la classe di istanze F4: entrypoint: gunicorn -b :$PORT -w 8 --threads 1 main:app
Nel runtime di Python 2, utilizzi il
script
campo per inoltrare le richieste in arrivo allo script della tua app.
Nel runtime di Python 3, devi utilizzare un framework web con routing in-app (ad esempio Flask o Django) anziché il campo script.
Per eseguire la migrazione del file app.yaml al runtime di Python 3, esegui una delle seguenti operazioni, a seconda che il file contenga gestori statici e gestori di script:
Se il file app.yaml contiene gestori statici, esegui una delle seguenti operazioni per assicurarti che le richieste di contenuti dinamici vengano indirizzate allo script della tua app:
Rimuovi tutti i campi script. Aggiungi poi un
campo entrypoint
per avviare un server web che esegue la tua app. Le richieste che non
corrispondono a nessuno dei tuoi gestori statici verranno indirizzate al server web
specificato nel campo entrypoint. Il server web
e il framework web della tua app sono responsabili dell'inoltro della richiesta
allo script corretto.
Sostituisci il valore di tutti i campi script con
auto. App Engine eseguirà automaticamente la tua app su un web server (supponendo che soddisfi alcuni requisiti) e tutte le richieste corrispondenti a un gestore di script verranno indirizzate al web server. Il server web e il framework web della tua app sono responsabili dell'indirizzamento della richiesta allo script corretto.
Se il file app.yamlnon contiene gestori statici, rimuovi tutti i campi script. Tutte le richieste alla tua app verranno indirizzate al server web dell'app e il framework dell'app indirizzerà la richiesta allo script corretto. Se vuoi, puoi aggiungere un campo entrypoint per personalizzare il comportamento di avvio predefinito.
Se il tuo app.yaml ha entrambi i tipi di gestori, puoi
comunque rimuovere tutti i gestori di script che verrebbero contrassegnati
auto, lasciando i gestori statici e i gestori
auto che richiedono altre direttive, come il
gestore solo per amministratori nell'esempio seguente.
Il runtime di Python 2 nell'ambiente standard di App Engine utilizza il
appengine_config.py
file.
Questo file viene ignorato nel runtime di Python 3. Il runtime Python 3 utilizza invece il file requirements.txt standard per installare le dipendenze, incluse quelle che utilizzano codice nativo.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThe Python 3 runtime on App Engine standard environment requires updates to the \u003ccode\u003eapp.yaml\u003c/code\u003e file, while the \u003ccode\u003eappengine_config.py\u003c/code\u003e file is no longer used.\u003c/p\u003e\n"],["\u003cp\u003eSeveral fields in the \u003ccode\u003eapp.yaml\u003c/code\u003e file are no longer supported in Python 3, including \u003ccode\u003eapi_version\u003c/code\u003e, \u003ccode\u003eapplication_readable\u003c/code\u003e, \u003ccode\u003ebuiltins\u003c/code\u003e, \u003ccode\u003ethreadsafe\u003c/code\u003e, and \u003ccode\u003elibraries\u003c/code\u003e, each having different changes in requirements or methodology.\u003c/p\u003e\n"],["\u003cp\u003eIf using the legacy bundled services, the \u003ccode\u003eapp_engine_apis\u003c/code\u003e field in \u003ccode\u003eapp.yaml\u003c/code\u003e must be set to \u003ccode\u003etrue\u003c/code\u003e, and it enables the use of \u003ccode\u003ehandlers: login\u003c/code\u003e; otherwise, Identity and Access Management (IAM) should be used.\u003c/p\u003e\n"],["\u003cp\u003eIn Python 3, the \u003ccode\u003escript\u003c/code\u003e field in \u003ccode\u003eapp.yaml\u003c/code\u003e handlers is replaced by in-app routing using a web framework like Flask or Django, and the \u003ccode\u003eentrypoint\u003c/code\u003e field is used to start the web server, which will handle the routing.\u003c/p\u003e\n"],["\u003cp\u003eIn the Python 3 runtime, dependencies are installed using the standard \u003ccode\u003erequirements.txt\u003c/code\u003e file instead of the \u003ccode\u003eappengine_config.py\u003c/code\u003e file used in Python 2, meaning the latter file can be removed.\u003c/p\u003e\n"]]],[],null,["# Preparing configuration files for the Python 3 runtime\n\nBefore you can run your app in the Python 3 runtime of the App Engine standard environment, you\nmay need to change some of the configuration files that App Engine uses:\n\n- `app.yaml`. This file contains information about your app's code, such as the\n runtime and the app handlers.\n\n- `appengine_config.py`. The Python 2 runtime uses this file to access\n third-party libraries and provide values for constants and \"hook functions\".\n The Python 3 runtime doesn't use this file.\n\nUpdating `app.yaml`\n-------------------\n\nThe behavior of some fields in your\n[`app.yaml` configuration file](/appengine/docs/standard/reference/app-yaml#entrypoint)\nhas been modified. Remove any fields that are no longer supported and update\nother fields as described in the following table.\n\nIf you use any of the deprecated fields, App Engine returns an error\nwhen you deploy your app.\n\nYou can use the following examples to compare the differences between the\n`app.yaml` files: \n\n### Python 2\n\n```yaml\nruntime: python27\napi_version: 1\nthreadsafe: true\n\nhandlers:\n- url: /\n script: home.app\n\n- url: /index\\.html\n script: home.app\n\n- url: /stylesheets\n static_dir: stylesheets\n\n- url: /(.*\\.(gif|png|jpg))$\n static_files: static/\\1\n upload: static/.*\\.(gif|png|jpg)$\n\n- url: /admin/.*\n script: admin.app\n login: admin\n\n- url: /.*\n script: not_found.app\n```\n\n### Python 3\n\n runtime: python313\n app_engine_apis: true\n\n handlers:\n - url: /stylesheets\n static_dir: stylesheets\n\n - url: /(.*\\.(gif|png|jpg))$\n static_files: static/\\1\n upload: static/.*\\.(gif|png|jpg)$\n\n - url: /admin/.*\n script: auto\n login: admin\n\n| **Note:** For Python 3 the preferred WSGI-compatible web server is `gunicorn`. When you use the optional `entrypoint` field in your [`app.yaml`](/appengine/docs/standard/reference/app-yaml#runtime_and_app_elements) configuration file, the timeout for `gunicorn` defaults to 30 seconds. To set a custom timeout, update the `entrypoint` field: for example, `entrypoint: gunicorn -b :$PORT --timeout=600`. In this case, [make sure you\n| have included `gunicorn`](/appengine/docs/standard/python3/runtime#entrypoint_best_practices) in your `requirements.txt` file.\n\nRemoving `appengine_config.py`\n------------------------------\n\nThe Python 2 runtime in the App Engine standard environment uses the\n[`appengine_config.py`](/appengine/docs/legacy/standard/python/tools/using-libraries-python-27)\nfile.\n\nThis file is ignored in the Python 3 runtime. Instead, the Python 3 runtime\nuses the standard `requirements.txt` file to\n[install dependencies](/appengine/docs/standard/python3/specifying-dependencies),\nincluding dependencies that use native code."]]