Quickstart: Create A Python App Using Azure App Service On Linux

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Quickstart: Create a Python app using

Azure App Service on Linux


 09/23/2021
 8 minutes to read

o C
o V
o K
o D
o J
o +4

Choose a framework

Flask Django

In this quickstart, you deploy a Python web app to App Service on Linux, Azure's highly
scalable, self-patching web hosting service. You use the local Azure command-line
interface (CLI) on a Mac, Linux, or Windows computer to deploy a sample with either the
Flask or Django frameworks. The web app you configure uses a basic App Service tier
that incurs a small cost in your Azure subscription.

Set up your initial environment


1. Have an Azure account with an active subscription. Create an account for free.
2. Install Python 3.6 or higher.
3. Install the Azure CLI, with which you run commands in any shell to provision and
configure Azure resources.

Open a terminal window and check your Python version is 3.6 or higher:

 Bash
 PowerShell
 Cmd
BashCopy
python3 --version

Check that your Azure CLI version is 2.0.80 or higher:

Azure CLICopy
az --version
Then sign in to Azure through the CLI:

Azure CLICopy
az login

This command opens a browser to gather your credentials. When the command finishes,
it shows JSON output containing information about your subscriptions.

Once signed in, you can run Azure commands with the Azure CLI to work with resources
in your subscription.

Having issues? Let us know.

Clone the sample

Clone the sample repository using the following command and navigate into the sample
folder. (Install git if you don't have git already.)

terminalCopy
git clone https://github.com/Azure-Samples/python-docs-hello-world

The sample contains framework-specific code that Azure App Service recognizes when
starting the app. For more information, see Container startup process.

Having issues? Let us know.

Run the sample

1. Navigate into in the python-docs-hello-world folder:

terminalCopy
cd python-docs-hello-world

2. Create a virtual environment and install dependencies:

o Bash
o PowerShell
o Cmd
BashCopy
# Linux systems only
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Git Bash on Windows only


py -3 -m venv .venv
source .venv\\scripts\\activate
pip install -r requirements.txt

If you're on a Windows system and see the error "'source' is not recognized
as an internal or external command," make sure you're either running in the
Git Bash shell, or use the commands shown in the Cmd tab above.

If you encounter "[Errno 2] No such file or directory: 'requirements.txt'.",


make sure you're in the python-docs-hello-world folder.

3. Run the development server.

terminalCopy
flask run

By default, the server assumes that the app's entry module is in app.py, as
used in the sample.

If you use a different module name, set the FLASK_APP environment variable


to that name.

If you encounter the error, "Could not locate a Flask application. You did not
provide the 'FLASK_APP' environment variable, and a 'wsgi.py' or 'app.py'
module was not found in the current directory.", make sure you're in
the python-docs-hello-world folder that contains the sample.

4. Open a web browser and go to the sample app at http://localhost:5000/.


The app displays the message Hello, World!.

5. In your terminal window, press Ctrl+C to exit the development server.

You might also like