Skip to content

Commit 306be0d

Browse files
Merge pull request #308541 from MicrosoftDocs/main
Auto Publish – main to live - 2025-11-19 23:00 UTC
2 parents affe4a5 + 61f136f commit 306be0d

101 files changed

Lines changed: 1066 additions & 496 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

articles/app-service/configure-language-python.md

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ ms.custom:
2626

2727
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.
2828

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).
3330

3431
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.
3532

@@ -84,7 +81,17 @@ The App Service build system, called Oryx, performs the following steps when you
8481
8582
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`.)
8683
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:
85+
- *requirements.txt*: Runs `pip install -r requirements.txt`.
86+
- *pyproject.toml* with *uv.lock*: Uses `uv`.
87+
- *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."
8895
8996
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.
9097
@@ -112,36 +119,13 @@ For more information on how App Service runs and builds Python apps in Linux, se
112119
> [!NOTE]
113120
> 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*).
114121
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):
122-
123-
```sh
124-
125-
poetry export -f requirements.txt --output requirements.txt --without-hashes
126-
127-
```
128-
129-
### Using uv
130-
131-
Generate *requirements.txt* by using [uv](https://docs.astral.sh/uv/concepts/projects/sync/#exporting-the-lockfile):
132-
133-
```sh
134-
135-
uv export --format requirements-txt --no-hashes --output-file requirements.txt
136-
137-
```
138122
139123
## Migrate existing applications to Azure
140124
141125
You can redeploy existing web applications to Azure as follows:
142126
143127
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.
145129
146130
1. **Database**. If your app depends on a database, create the necessary resources on Azure as well.
147131
@@ -248,9 +232,9 @@ This container has the following characteristics:
248232

249233
- 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.
250234

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.
252236

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.
254238

255239
- 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`.
256240

@@ -403,7 +387,7 @@ Use the following steps to access the deployment logs:
403387
1. On the **Logs** tab, select the **Commit ID** for the most recent commit.
404388
1. On the **Log details** page that appears, select the **Show Logs** link that appears next to **Running oryx build**.
405389

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 requirements file isn't named *requirements.txt* or doesn't appear in 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.
407391

408392
## Open SSH session in a browser
409393

@@ -423,7 +407,7 @@ In general, the first step in troubleshooting is to use App Service diagnostics:
423407
1. Select **Availability and Performance**.
424408
1. Examine the information in **Application Logs**, **Container Crash**, and **Container Issues**, where the most common issues appear.
425409

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.
427411

428412
The following sections provide guidance for specific issues.
429413

@@ -459,9 +443,9 @@ The following sections provide guidance for specific issues.
459443

460444
#### Could not find setup.py or requirements.txt
461445

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.
463447

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 and is 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.
465449

466450
#### ModuleNotFoundError when app starts
467451

Binary file not shown.
-20.4 KB
Loading
-15.9 KB
Loading
-39 KB
Loading
-121 KB
Loading
-159 KB
Loading
-44.6 KB
Loading
-12.3 KB
Loading
-34 KB
Loading

0 commit comments

Comments
 (0)