You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/app-service/configure-language-python.md
+19-35Lines changed: 19 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,7 @@ ms.custom:
26
26
27
27
This article describes how [Azure App Service](overview.md) runs Python apps, how you can migrate existing apps to Azure, and how you can customize the behavior of App Service when you need to. Python apps must be deployed with all the required [pip](https://pypi.org/project/pip/) modules.
28
28
29
-
The App Service deployment engine automatically activates a virtual environment and runs `pip install -r requirements.txt` when you deploy a [Git repository](deploy-local-git.md) or when you deploy a [zip package](deploy-zip.md)[with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy).
30
-
31
-
> [!NOTE]
32
-
> App Service currently requires `requirements.txt` in your project's root directory even if you have a `pyproject.toml`. See [Generate requirements.txt from pyproject.toml](#generate-requirementstxt-from-pyprojecttoml) for recommended approaches.
29
+
The App Service deployment engine automatically activates a virtual environment and installs dependencies from a `requirements.txt`, `pyproject.toml`, or `setup.py` file when you deploy a [Git repository](deploy-local-git.md) or when you deploy a [zip package](deploy-zip.md)[with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy).
33
30
34
31
This article provides key concepts and instructions for Python developers who use a built-in Linux container in App Service. If you've never used App Service, first complete the [Python quickstart](quickstart-python.md) and [Flask](tutorial-python-postgresql-app-flask.md), [Django](tutorial-python-postgresql-app-django.md), or [FastAPI](tutorial-python-postgresql-app-fastapi.md) with PostgreSQL tutorial.
35
32
@@ -84,7 +81,17 @@ The App Service build system, called Oryx, performs the following steps when you
84
81
85
82
1. Run a custom pre-build script, if that step is specified by the `PRE_BUILD_COMMAND` setting. (The script can itself run other Python and Node.js scripts, pip and npm commands, and Node-based tools like Yarn, for example, `yarn install` and `yarn build`.)
86
83
87
-
1. Run `pip install -r requirements.txt`. The *requirements.txt* file must be in the project's root folder. If it's not, the build process reports the error "Could not find setup.py or requirements.txt; Not running pip install."
84
+
1. Install dependencies. The build system checks for the following files in the project root:
- *pyproject.toml* with *poetry.lock*: Uses `poetry`.
88
+
- *pyproject.toml*: Uses `poetry`.
89
+
- *setup.py*: Runs `pip install .`.
90
+
91
+
> [!NOTE]
92
+
> If *pyproject.toml* is present but *uv.lock* is missing, App Service defaults to using Poetry, even if *poetry.lock* is also missing. To use `uv`, you must include *uv.lock* in your deployment.
93
+
94
+
If none of these files are found, the build process reports the error "Could not find setup.py or requirements.txt; Not running pip install."
88
95
89
96
1. If *manage.py* is found in the root of the repository (which indicates a Django app), run `manage.py collectstatic`. However, if the `DISABLE_COLLECTSTATIC` setting is `true`, this step is skipped.
90
97
@@ -112,36 +119,13 @@ For more information on how App Service runs and builds Python apps in Linux, se
112
119
> [!NOTE]
113
120
> Always use relative paths in all pre-build and post-build scripts because the build container in which Oryx runs is different from the runtime container in which the app runs. Never rely on the exact placement of your app project folder within the container (for example, that it's placed under *site/wwwroot*).
114
121
115
-
## Generate requirements.txt from pyproject.toml
116
-
117
-
Currently, App Service doesn't directly support `pyproject.toml`. If you use tools like Poetry or uv, the recommended approach is to generate a compatible *requirements.txt* file before deployment in your project's root:
118
-
119
-
### Using Poetry
120
-
121
-
Generate *requirements.txt* by using [Poetry](https://python-poetry.org/) with the [export plugin](https://github.com/python-poetry/poetry-plugin-export):
You can redeploy existing web applications to Azure as follows:
142
126
143
127
1. **Source repository**. Maintain your source code in a suitable repository, like GitHub, which enables you to set up continuous deployment later in this process.
144
-
- Your *requirements.txt* file must be at the root of your repository if you want App Service to automatically install the necessary packages.
128
+
- Your dependency file (such as *requirements.txt*, *pyproject.toml*, or *setup.py*) must be at the root of your repository if you want App Service to automatically install the necessary packages.
145
129
146
130
1. **Database**. If your app depends on a database, create the necessary resources on Azure as well.
147
131
@@ -248,9 +232,9 @@ This container has the following characteristics:
248
232
249
233
- By default, the base container image includes only the Flask web framework, but the container supports other frameworks that are WSGI-compliant and compatible with Python 3.6 and later, such as Django.
250
234
251
-
- To install other packages, such as Django, create a [*requirements.txt*](https://pip.pypa.io/en/stable/user_guide/#requirements-files) file in the root of your project that specifies your direct dependencies. App Service then installs those dependencies automatically when you deploy your project.
235
+
- To install other packages, such as Django, create a [*requirements.txt*](https://pip.pypa.io/en/stable/user_guide/#requirements-files), *pyproject.toml*, or *setup.py* file in the root of your project that specifies your direct dependencies. App Service then installs those dependencies automatically when you deploy your project.
252
236
253
-
The *requirements.txt*file must be in the project root or dependencies won't be installed. If this file isn't in the root, the build process reports the error "Could not find setup.py or requirements.txt; Not running pip install." If you encounter this error, check the location of your requirements file.
237
+
The dependency file must be in the project root or dependencies won't be installed. If this file isn't in the root, the build process reports the error "Could not find setup.py or requirements.txt; Not running pip install." If you encounter this error, check the location of your requirements file.
254
238
255
239
- App Service automatically defines an environment variable named `WEBSITE_HOSTNAME` that contains the web app's URL, such as `msdocs-hello-world.azurewebsites.net`. It also defines `WEBSITE_SITE_NAME`, which contains the name of your app, such as `msdocs-hello-world`.
256
240
@@ -403,7 +387,7 @@ Use the following steps to access the deployment logs:
403
387
1. On the **Logs** tab, select the **Commit ID** for the most recent commit.
404
388
1. On the **Log details** page that appears, select the **Show Logs** link that appears next to **Running oryx build**.
405
389
406
-
Build issues, like incorrect dependencies in*requirements.txt*and errors in pre-build or post-build scripts, appear in these logs. Errors also appear if your requirementsfile isn't named *requirements.txt* or doesn't appearin the root folder of your project.
390
+
Build issues, like incorrect dependencies in your dependency file and errors in pre-build or post-build scripts, appear in these logs. Errors also appear if your dependency file isn't found in the root folder of your project.
407
391
408
392
## Open SSH session in a browser
409
393
@@ -423,7 +407,7 @@ In general, the first step in troubleshooting is to use App Service diagnostics:
423
407
1. Select **Availability and Performance**.
424
408
1. Examine the information in **Application Logs**, **Container Crash**, and **Container Issues**, where the most common issues appear.
425
409
426
-
Next, examine both the [deployment logs](#access-deployment-logs) and the [app logs](#access-diagnostic-logs) for any error messages. These logs often identify specific issues that can prevent app deployment or app startup. For example, the build can fail if your *requirements.txt* file has the wrong file name or isn't present in your project root folder.
410
+
Next, examine both the [deployment logs](#access-deployment-logs) and the [app logs](#access-diagnostic-logs) for any error messages. These logs often identify specific issues that can prevent app deployment or app startup. For example, the build can fail if your dependency file isn't present in your project root folder.
427
411
428
412
The following sections provide guidance for specific issues.
429
413
@@ -459,9 +443,9 @@ The following sections provide guidance for specific issues.
459
443
460
444
#### Could not find setup.py or requirements.txt
461
445
462
-
-**The log stream shows "Could not find setup.py or requirements.txt; Not running pip install."** The Oryx build process failed to find your *requirements.txt*file.
446
+
-**The log stream shows "Could not find setup.py or requirements.txt; Not running pip install."** The Oryx build process failed to find your *requirements.txt*, *pyproject.toml*, or *setup.py* file.
463
447
464
-
- Connect to the web app's container via [SSH](#open-ssh-session-in-a-browser) and verify that *requirements.txt* is named correctly and exists directly under *site/wwwroot*. If it doesn't exist, make sure the file exists in your repository andis included in your deployment. If it exists in a separate folder, move it to the root.
448
+
- Connect to the web app's container via [SSH](#open-ssh-session-in-a-browser) and verify that your dependency file is named correctly and exists directly under *site/wwwroot*. If it doesn't exist, make sure the file exists in your repository and is included in your deployment. If it exists in a separate folder, move it to the root.
0 commit comments