기본적으로 Python 런타임 빌드팩은 최신 Python 인터프리터 안정화 버전을 사용합니다. 애플리케이션에 특정 버전이 필요한 경우 애플리케이션 루트 디렉터리에 .python-version 파일을 포함하여 버전을 지정하면 됩니다.
3.9.9
GOOGLE_PYTHON_VERSION 사용
GOOGLE_PYTHON_VERSION 환경 변수를 통해 Python 버전을 지정할 수도 있습니다.
두 구성이 모두 설정된 경우 GOOGLE_PYTHON_VERSION 값이 .python-version 파일보다 우선 적용됩니다. 기본적으로 .python-version 파일과 GOOGLE_PYTHON_VERSION 환경 변수가 모두 지정되지 않은 경우 Python의 최신 LTS 버전이 사용됩니다.
Artifact Registry Python 저장소는 Python 함수의 비공개 종속 항목을 호스팅할 수 있습니다. Cloud Build에서 애플리케이션을 빌드할 때 Python 빌드팩은 Cloud Build 서비스 계정의 Artifact Registry 사용자 인증 정보를 자동으로 생성합니다.
추가 사용자 인증 정보를 생성하지 않고도 requirements.txt에 Artifact Registry URL만 포함하면 됩니다. 예를 들면 다음과 같습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-18(UTC)"],[[["\u003cp\u003eThe Python buildpack allows specifying the Python version via a \u003ccode\u003e.python-version\u003c/code\u003e file or the \u003ccode\u003eGOOGLE_PYTHON_VERSION\u003c/code\u003e environment variable, with the environment variable taking precedence.\u003c/p\u003e\n"],["\u003cp\u003eApplication dependencies are managed through a \u003ccode\u003erequirements.txt\u003c/code\u003e file in the root directory, using pip, allowing for package name and optional version specification, as well as private dependencies from Artifact Registry.\u003c/p\u003e\n"],["\u003cp\u003ePip behavior can be configured using environment variables, such as \u003ccode\u003ePIP_DEFAULT_TIMEOUT\u003c/code\u003e, to modify pip command execution.\u003c/p\u003e\n"],["\u003cp\u003eGunicorn serves as the default WSGI HTTP server, and its settings, along with the application entrypoint, can be customized using a \u003ccode\u003eProcfile\u003c/code\u003e or the \u003ccode\u003eGOOGLE_ENTRYPOINT\u003c/code\u003e environment variable, while requiring that gunicorn be present in the requirements.txt when overriding defaults.\u003c/p\u003e\n"]]],[],null,["# Build a Python application\n\nBuildpacks support language-idiomatic configuration through environment\nvariables.\n\nSpecify the Python version\n--------------------------\n\nBy default the Python Runtime buildpack uses the latest stable version of the Python interpreter. If your application requires a specific version, you can specify one by including a `.python-version` file in your application's root directory. \n\n 3.13\n\n### Use `GOOGLE_PYTHON_VERSION`\n\nIt is also possible to specify the Python version via the\n`GOOGLE_PYTHON_VERSION` environment variable.\nIf both configurations are set, the `GOOGLE_PYTHON_VERSION` value takes\nprecedence over the `.python-version` file. By default, when both the\n`.python-version` file and `GOOGLE_PYTHON_VERSION` environment variable are not\nspecified, then the latest LTS version of Python is used.\n\nTo configure the buildpack to use Python 3.13 when deploying your app: \n\n pack build sample-python --builder=gcr.io/buildpacks/builder \\\n --env GOOGLE_PYTHON_VERSION=\"3.13.x\"\n\n\nYou can also use a `project.toml` project descriptor to encode\nthe environment variable alongside your project files. See instructions on\n[building the application with environment variables](/docs/buildpacks/set-environment-variables#build_the_application_with_environment_variables)).\n\nSpecify dependencies with `pip`\n-------------------------------\n\nThe Python buildpack supports managing application dependencies using pip. Your application dependencies should be declared in a `requirements.txt` file the root directory.\n\nThe `requirements.txt` file contains one line per package. Each line contains\nthe package name, and optionally, the requested version. For more details, see\nthe [`requirements.txt` reference](https://pip.pypa.io/en/stable/user_guide/#requirements-files).\n\nThe following is an example `requirements.txt` file: \n\n```\nrequests==2.20.0\nnumpy\n```\n\n### Configure pip\n\nIt is possible to configure the behavior of pip [using environment variables](https://pip.pypa.io/en/stable/topics/configuration/): \n\n pack build sample-python --builder=gcr.io/buildpacks/builder \\\n --env PIP_DEFAULT_TIMEOUT='60'\n\n### Private dependencies from Artifact Registry\n\nAn [Artifact Registry Python repository](/artifact-registry/docs/python/store-python)\ncan host private dependencies for your Python function. When building an application on\nCloud Build, the Python buildpack will automatically generate Artifact Registry\ncredentials for the [Cloud Build service account](/build/docs/cloud-build-service-account).\nYou only need to include the Artifact Registry URL in your `requirements.txt`\nwithout generating additional credentials. For example: \n\n --extra-index-url \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREPOSITORY_URL\u003c/span\u003e\u003c/var\u003e\n sampleapp\n Flask==0.10.1\n google-cloud-storage\n\nApplication entrypoint\n----------------------\n\nThe following section describes the default entrypoint for the Python buildpack.\n\n### Entrypoint for Cloud Run source deploys\n\nThis feature is only available if you [deploy your source code](/run/docs/deploying-source-code) to Cloud Run with the Python runtime. This feature\nisn't applicable if you are building your container image directly using\n`pack build` outside of the Cloud Run source deploy process.\n\nThe [Python buildpack](/docs/buildpacks/python) supports\nmodern web frameworks such as [FastAPI](https://fastapi.tiangolo.com/), [Gradio](https://www.gradio.app/), and [Streamlit](https://streamlit.io/).\n\n#### Python version 3.12 and earlier\n\nIf you're using Python version 3.12 and earlier, the Python\nbuildpack defaults to using [Gunicorn](https://gunicorn.org/)\nas the WSGI HTTP server for your workload. The Python buildpack sets the default entrypoint to `gunicorn -b :8080 main:app`.\n\n#### Python version 3.13 and later\n\nFor Python version 3.13 and later, the Python buildpack\nsets the default entrypoint for [Cloud Run source deploys](/run/docs/deploying-source-code) based on the web server or framework configuration in your\n`requirements.txt` file. This default setting applies only to Cloud Run\nservice source deployments, not to Cloud Run functions.\n\nWhen you deploy a Cloud Run service from source using the Python runtime,\nthe buildpack determines the Python version and the default\nentrypoint in the following ways:\n\n- If you don't specify a Python version in your source files,\n the Python buildpack sets the default to the [latest supported Python version](/docs/buildpacks/runtime-support#python). The buildpack determines the default entrypoint based on the web server or framework you've\n [configured in your `requirements.txt` file](#default-entrypoint).\n\n- If you don't specify a web server or a framework in your `requirements.txt` file, the Python buildpack defaults to using Gunicorn as the WSGI HTTP server for your workload. The Python buildpack sets the default entrypoint to `gunicorn -b :8080 main:app`.\n\n- The Python buildpack sets the default entrypoint\n based on the following order of precedence, as defined in the `requirements.txt`\n file:\n\n 1. `gunicorn`\n 2. `uvicorn`\n 3. `gradio`\n 4. `streamlit`.\n\n#### Configure the web server or framework\n\nFor each common Python configurations in the `requirements.txt` file, the following table shows the default entrypoints when deploying to Cloud Run from source:\n\nTo avoid deployment failures, use a [supported Python\nversion](/docs/buildpacks/runtime-support#python) in your source files, and\nspecify a web server in your `requirements.txt` file.\n\nAlternatively, you can also specify the entrypoint by running the following source deploy command: \n\n gcloud run deploy \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e --source . --set-build-env-vars GOOGLE_ENTRYPOINT=\"\u003cvar translate=\"no\"\u003eENTRYPOINT\u003c/var\u003e\"\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e: the name of the service you want to deploy to.\n- \u003cvar translate=\"no\"\u003eENTRYPOINT\u003c/var\u003e: the default entrypoint you want to use for your source code.\n\nIf you're unable to deploy your source code to Cloud Run or find errors\nin the logs, see the [Cloud Run troubleshooting guide](/run/docs/troubleshooting#source-deploy-errors).\n\n### Entrypoint for all other deployments\n\nThe Python buildpack uses [Gunicorn](https://gunicorn.org/)\nas the default WSGI HTTP server for your workload. Apps built with the Python\nbuildpack start the `gunicorn` process with default settings,\nsimilar to running: \n\n gunicorn --bind :8080 main:app\n\n### Customize the application entrypoint\n\nYou can customize the applications start command by using a `Procfile` or an environment variable. You might need to do this to customize the [default entrypoint configurations](/docs/buildpacks/python#default-entrypoint).\n\nYou can create a `Procfile` with your custom settings in the root directory.\nExample: \n\n web: gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app\n\n| **Important:** When you override the Gunicorn defaults, you must include `gunicorn` as a package dependency in your project's `requirements.txt` file.\n\nAlternatively, you can use the `GOOGLE_ENTRYPOINT` environment variable with\nthe `pack` command. Example: \n\n pack build sample-python \\\n --builder gcr.io/buildpacks/builder\n --env \"GOOGLE_ENTRYPOINT='gunicorn --bind :$PORT main:app'\"\n\nEnvironment Variables\n---------------------\n\nThe Python buildpack supports the following environment variables to customize your container\n\n### `PIP_\u003ckey\u003e`\n\nSee pip [documentation](https://pip.pypa.io/en/stable/user_guide/#environment-variables).\n\n**Example:** `PIP_DEFAULT_TIMEOUT=60` sets `--default-timeout=60` for `pip` commands."]]