Share via

Django App Fails to Start on Azure App Service Linux – ModuleNotFoundError: No module named 'django'

NITIN PARMAR-Kritva 20 Reputation points
2026-03-11T04:58:43.3+00:00

Hi Support,
I am deploying a Django application on Azure App Service (Linux). The application fails to start and logs show:

ModuleNotFoundError: No module named 'django'

Python runtime: 3.13 Startup command: gunicorn --bind=0.0.0.0 --timeout 600 ledger_project.wsgi:application

requirements.txt is uploaded but dependencies are not being installed.

Deployment was done via FTP. SCM_DO_BUILD_DURING_DEPLOYMENT environment variable is set to true.

How can I ensure Azure installs the packages from requirements.txt and starts the Django application successfully?

Attaching App service runtime logs below.
Azure appservice_linux_runtime_logs.txt

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.

0 comments No comments

Answer accepted by question author
  1. Q&A Assist
    2026-03-11T04:59:02.2066667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error indicates that Django (and likely other dependencies) are not installed in the App Service container, so Gunicorn cannot import django when starting ledger_project.wsgi.

    To have Azure App Service install packages from requirements.txt and start the Django app correctly, ensure all of the following are true and aligned with how App Service builds Python apps:

    1. Place requirements.txt in the correct location
      • requirements.txt must be in the project root that is deployed to App Service, and end up directly under /site/wwwroot in the container.
      • If requirements.txt is in a subfolder (for example, /site/wwwroot/src/requirements.txt), Oryx will not find it and will log: Could not find setup.py or requirements.txt; Not running pip install.
      • Use SSH into the app container and verify:
        • cd /site/wwwroot
        • ls shows requirements.txt in that directory.
    2. Do not deploy a local virtual environment
      • If a local virtual environment (for example, venv/, .venv/, env/) is deployed along with the code, it can cause ModuleNotFoundError issues because virtual environments are not portable across machines.
      • Remove any virtual environment folders from the deployed content. Only deploy application code and requirements.txt.
      • Let App Service create and manage its own virtual environment and install packages.
    3. Use SCM_DO_BUILD_DURING_DEPLOYMENT=1 correctly
      • Ensure the app setting is configured exactly as expected:
        • Name: SCM_DO_BUILD_DURING_DEPLOYMENT
        • Value: 1 (string 1, not true or True).
      • After setting this, redeploy the app so that Oryx runs and installs packages from requirements.txt.
    4. Redeploy using a build-aware method (instead of raw FTP)
      • FTP upload alone does not trigger the Oryx build process that installs Python packages.
      • Use one of these deployment methods so that Oryx runs and reads requirements.txt:
        • az webapp up / az webapp deployment (CLI-based deployment)
        • Git or GitHub Actions deployment
        • VS Code App Service extension deployment
      • If FTP must be used, combine it with a build trigger by setting SCM_DO_BUILD_DURING_DEPLOYMENT=1 and then redeploy via a supported method at least once so the container is built with dependencies.
    5. Confirm the app is detected as Django and the startup command is valid
      • Ensure the Django project structure matches App Service expectations:
        • A wsgi.py file exists in the Django project module (for example, ledger_project/wsgi.py).
      • The default App Service behavior for Django is:
             gunicorn --bind=0.0.0.0 --timeout 600 <module>.wsgi
        
      • The custom startup command being used:
             gunicorn --bind=0.0.0.0 --timeout 600 ledger_project.wsgi:application
        
        is valid as long as ledger_project is the folder containing wsgi.py and that folder is on PYTHONPATH (typically the project root /site/wwwroot).
    6. Check logs to verify package installation and startup
      • After redeploying with SCM_DO_BUILD_DURING_DEPLOYMENT=1 and a supported deployment method:
        • Use App Service diagnostics (Diagnose and solve problemsAvailability and Performance) to check Application Logs and Container Issues for:
          • Oryx build logs showing pip install -r requirements.txt.
          • Any Could not find setup.py or requirements.txt; Not running pip install. messages.
        • Stream logs using az webapp log tail to confirm that Gunicorn starts without ModuleNotFoundError.

    If all of the above are in place—requirements.txt in /site/wwwroot, no virtualenv deployed, SCM_DO_BUILD_DURING_DEPLOYMENT=1, and a build-aware deployment method—App Service will run Oryx, install Django and other dependencies, and the Django application will start successfully under Gunicorn.


    References:

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Aditya N 2,460 Reputation points Microsoft External Staff Moderator
    2026-03-13T03:17:04.13+00:00

    Hello @NITIN PARMAR-Kritva

    Thank you for reaching out Microsoft Q&A.

    Main reason is Django and dependencies were never installed in the container. Look for path, open ssh and run

    cd /home/site/wwwroot

    ls -la

    requirement.tt should appear here.

    Under Configuration > Application settings set SCM_DO_BUILD_DURING_DEPLOYMENT = 1

    Perform Oryx build and deploy using deploy command.

    Please comment below if you have any queries.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.