Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
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:
- Place
requirements.txtin the correct location-
requirements.txtmust be in the project root that is deployed to App Service, and end up directly under/site/wwwrootin the container. - If
requirements.txtis 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 -
lsshowsrequirements.txtin that directory.
-
-
- 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 causeModuleNotFoundErrorissues 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.
- If a local virtual environment (for example,
- Use
SCM_DO_BUILD_DURING_DEPLOYMENT=1correctly- Ensure the app setting is configured exactly as expected:
- Name:
SCM_DO_BUILD_DURING_DEPLOYMENT - Value:
1(string1, nottrueorTrue).
- Name:
- After setting this, redeploy the app so that Oryx runs and installs packages from
requirements.txt.
- Ensure the app setting is configured exactly as expected:
- 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=1and then redeploy via a supported method at least once so the container is built with dependencies.
- Confirm the app is detected as Django and the startup command is valid
- Ensure the Django project structure matches App Service expectations:
- A
wsgi.pyfile exists in the Django project module (for example,ledger_project/wsgi.py).
- A
- The default App Service behavior for Django is:
gunicorn --bind=0.0.0.0 --timeout 600 <module>.wsgi - The custom startup command being used:
is valid as long asgunicorn --bind=0.0.0.0 --timeout 600 ledger_project.wsgi:applicationledger_projectis the folder containingwsgi.pyand that folder is onPYTHONPATH(typically the project root/site/wwwroot).
- Ensure the Django project structure matches App Service expectations:
- Check logs to verify package installation and startup
- After redeploying with
SCM_DO_BUILD_DURING_DEPLOYMENT=1and a supported deployment method:- Use App Service diagnostics (Diagnose and solve problems → Availability 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.
- Oryx build logs showing
- Stream logs using
az webapp log tailto confirm that Gunicorn starts withoutModuleNotFoundError.
- Use App Service diagnostics (Diagnose and solve problems → Availability and Performance) to check Application Logs and Container Issues for:
- After redeploying with
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: