[[["容易理解","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-19 (世界標準時間)。"],[[["\u003cp\u003ePython application dependencies are declared in a \u003ccode\u003erequirements.txt\u003c/code\u003e file, which is used during deployment to automatically install the specified packages.\u003c/p\u003e\n"],["\u003cp\u003eIt is recommended to use \u003ccode\u003evenv\u003c/code\u003e for local development to isolate application dependencies and ensure consistency between local and deployed environments.\u003c/p\u003e\n"],["\u003cp\u003eAny Linux-compatible Python package, including those with native extensions, can be used in the App Engine flexible environment.\u003c/p\u003e\n"],["\u003cp\u003eWeb frameworks like Flask, Django, and Pyramid, can be integrated into applications by adding them to the \u003ccode\u003erequirements.txt\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eCloud Client Libraries, such as those for Datastore and Cloud Storage, can be easily installed using \u003ccode\u003epip\u003c/code\u003e and configured for automatic authentication via the Google Cloud CLI.\u003c/p\u003e\n"]]],[],null,["# Specifying dependencies\n\nDependencies for python applications are declared in a standard\n[`requirements.txt`](https://pip.pypa.io/en/latest/user_guide/#requirements-files)\nfile. For example: \n\n Flask==\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eMAJOR\u003c/span\u003e\u003c/var\u003e.\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eMINOR\u003c/span\u003e\u003c/var\u003e.\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePATCH\u003c/span\u003e\u003c/var\u003e\n google-cloud-storage\n\nReplace \u003cvar translate=\"no\"\u003eMAJOR\u003c/var\u003e, \u003cvar translate=\"no\"\u003eMINOR\u003c/var\u003e, and \u003cvar translate=\"no\"\u003ePATCH\u003c/var\u003e with the desired\n[Flask version numbers](https://pypi.org/project/Flask/#history).\n\nYou can use any Linux-compatible Python package in the App Engine flexible\nenvironment, including packages that require native (C) extensions.\n\nThe Python runtime will [automatically install](/appengine/docs/flexible/python/runtime#dependencies) all dependencies\ndeclared in your `requirements.txt` during deployment.\n\nInstalling dependencies locally\n-------------------------------\n\nWhen developing and testing your application locally, we recommended you use\n[`venv`](https://docs.python.org/3/library/venv.html) to isolate your application's dependencies from your system\npackages. This also ensures that your dependencies will be the same version on\nyour local machine and the deployed application.\n\nTo use `venv` to install dependencies, complete the following\nsteps:\n\n\n### Mac OS / Linux\n\n| Note: These instructions describe how to set up a virtual environment in Python 3. For Python 2 apps, use [virtualenv](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#installing-virtualenv) to set up a virtual environment.\n\n1. Create an [isolated Python environment](/python/docs/setup#installing_and_using_virtualenv): \n\n python3 -m venv env\n source env/bin/activate\n\n2. If you're not in the directory that contains the sample code, navigate to the directory that contains the `hello_world` sample code. Then install dependencies: \n\n cd \u003cvar translate=\"no\"\u003eYOUR_SAMPLE_CODE_DIR\u003c/var\u003e\n pip install -r requirements.txt\n\n### Windows\n\n| Note: These instructions describe how to set up a virtual environment in Python 3. For Python 2 apps, use [virtualenv](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#installing-virtualenv) to set up a virtual environment.\n\nUse\nPowerShell to run your Python packages.\n\n1. Locate your installation of [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows).\n2. Right-click on the shortcut to PowerShell and start it as an administrator.\n3. Create an [isolated Python environment](/python/docs/setup#installing_and_using_virtualenv). \n\n python -m venv env\n .\\env\\Scripts\\activate\n\n4. Navigate to your project directory and install dependencies. If you're not in the directory that contains the sample code, navigate to the directory that contains the `hello_world` sample code. Then, install dependencies: \n\n cd \u003cvar translate=\"no\"\u003eYOUR_SAMPLE_CODE_DIR\u003c/var\u003e\n pip install -r requirements.txt\n\nThis ensures that when you run your app locally, only the\ndependencies that are declared in the `requirements.txt` file are available.\nThe dependencies installed by App Engine during deployment are based on\nthe contents of the `requirements.txt` file, not the contents of the `env/`\ndirectory.\n| **Tip:** Often you will not know your exact dependencies. After you install dependencies, you can use [`pip freeze`](https://pip.pypa.io/en/latest/reference/pip_freeze.html#pip-freeze) to write the name and version of all installed packages to your `requirements.txt`.\n\nInstalling a web framework\n--------------------------\n\nYou'll need to use a web framework to enable your app to serve web requests.\nYou can use any Python web framework including the following:\n\n- [Flask](http://flask.pocoo.org/)\n- [Django](https://www.djangoproject.com/)\n- [Pyramid](http://www.pylonsproject.org/)\n- [Bottle](http://bottlepy.org/)\n- [web.py](http://webpy.org/)\n- [Tornado](http://www.tornadoweb.org/)\n\nTo use a particular web framework, just add it to your `requirements.txt`: \n\n Flask==\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eMAJOR\u003c/span\u003e\u003c/var\u003e.\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eMINOR\u003c/span\u003e\u003c/var\u003e.\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePATCH\u003c/span\u003e\u003c/var\u003e\n\nInstalling a WSGI server\n------------------------\n\nSome web frameworks have built-in WSGI servers; however, few of them are\nsuitable for serving production traffic. Most web applications use a standalone\n[WSGI server](http://www.fullstackpython.com/wsgi-servers.html) such as\n[Gunicorn](http://gunicorn.org/),\n[uWSGI](http://uwsgi-docs.readthedocs.org/en/latest/) or\n[Waitress](https://pylons.readthedocs.org/projects/waitress/en/latest/).\nFor more information on installing, configuring, and using a WSGI server see\n[application startup](/appengine/docs/flexible/python/runtime#application_startup).\n\nInstalling the Cloud Client Libraries\n-------------------------------------\n\nThe [Cloud Client Libraries for Python](/python/docs/reference) is a client library for\naccessing Google Cloud services that significantly reduces the boilerplate\ncode you have to write. The library provides high-level API abstractions so\nthey're easier to understand. It embraces idioms of Python, works well with the\nstandard Python library, and integrates better with your codebase.\n\nFor example, you can install the corresponding Python client library for\n[Datastore](/datastore) or [Cloud Storage](/storage) to integrate those\nservices with your app.\n\nTo install the Python client library for Cloud Datastore:\n\n1. Install the client library locally by using `pip`:\n\n \u003cbr /\u003e\n\n ```\n pip install google-cloud-datastore\n ```\n\n \u003cbr /\u003e\n\n2. Set up authentication. You can configure the Cloud Client Libraries for Python\n to [handle authentication automatically](/docs/authentication/client-libraries).\n The client library can automatically handle authentication for you locally as\n well by using the [Google Cloud CLI](/sdk/docs).\n\n gcloud auth login\n\n3. Use the [Datastore Client Libraries reference](/datastore/docs/reference/libraries) to implement support for the Cloud Datastore service in your app.\n\nFor a complete list of all of the Cloud Client Libraries for Python for the supported\nGoogle Cloud services, see [APIs \\& Python Libraries](/python/docs/reference)."]]