Forum Discussion

WernerKoen's avatar
WernerKoen
Copper Contributor
Mar 11, 2025

Unable to get Python3.12 running on Azure App services

Good day,

I am having endless trouble getting a python app to run on azure service apps. I cannot find anywhere to install modules like pip, which I need to install openai.

Can someone please assist as I've been struggling for 2 days now... I am fairly new to this process.

Deployment goes through, but it fails to install pip modules

Thank you in advance!

W

 

2 Replies

  • Take this:

     

    • Ensure a requirements.txt File:
      • Azure App Services automatically installs Python dependencies listed in a requirements.txt file during deployment. Make sure this file is in the root directory of your project and includes all the required modules (e.g., openai).
    • Check Python Version:
      • Azure App Services supports specific Python versions. Verify that Python 3.12 is supported or consider using a supported version. You can check and set the Python version using the Azure CLI:
    az webapp config set --resource-group <resource-group-name> --name <app-name> --linux-fx-version "PYTHON|3.12"
    
    • Enable Build Automation:
      • Ensure the SCM_DO_BUILD_DURING_DEPLOYMENT setting is enabled. This triggers the build process, including the installation of pip modules. You can enable it in the Azure portal under "Configuration" or via the Azure CLI:
    az webapp config appsettings set --resource-group <resource-group-name> --name <app-name> --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
    
    • Use a Virtual Environment:
      • If you're deploying manually, activate a virtual environment locally, install the required modules, and then deploy the app along with the virtual environment.
    • Check Deployment Logs:
      • Review the deployment logs in the Azure portal to identify any specific errors during the pip installation process.
    • Consider a Custom Docker Image:
      • If Python 3.12 isn't natively supported, you can create a custom Docker image with Python 3.12 and all the required modules pre-installed. Deploy this image to Azure App Services.
  • HaseebAsghar's avatar
    HaseebAsghar
    Brass Contributor

    Simple Steps to Deploy Django on Azure App Service with Python 3.12
    1. Create Web App in Azure
    Go to Azure Portal > App Services
    Click Create Web App
    Select Python 3.12 (or latest)
    2. Setup Django Project on Your PC
    # Create project django-admin startproject myproject cd myproject # Create virtual environment python -m venv venv source venv/bin/activate # (Windows: venv \Scripts \ activate) # Install required packages pip install django gunicorn openai # Add other dependencies # Freeze dependencies pip freeze > requirements.txt
    3. Configure requirements.txt

    Ensure it includes:

    django gunicorn openai
    4. Deploy to Azure
    Use Git or ZIP Deploy: Push code to Azure using GitHub, Azure CLI, or ZIP
    Configure Startup Command in Azure: gunicorn --workers=4 myproject.wsgi
    Check Logs in Azure > App Service > Log Stream
    5. Apply Migrations & Run

    SSH into Azure Web App and run:

    python manage.py migrate python manage.py createsuperuser

    Your Django app is now live on Azure! 🚀

Resources