3

I am attempting to deploy a Django app to a Linux server via an Azure App Service. During the deployment via Azure Devops Pipelines, all requirements are installed from my requirements.txt file in the root directory of my project.

I have used the Kudu console to confirm the dependencies are installed to /antenv/lib/python3.7/site-packages on the server, however, the app crashes due to an error:

ModuleNotFoundError: No module named 'django'

I am beginning to think the virtual environment may be failing to actually start but do not know how to check or how to start it if this is the case.

Has anyone had a similar issue to this during their deployment? If so how did you resolve it? Any advise is much appreciated. Thank you!

  • Same here! Updated on row in my code (which has no relation to installed modules) and uploaded back to Azure web app. Result: flask_migrate is not found, along with python-decouple. PS: both are in my requirements.txt and always worked just fine! – Julio S. Oct 15 '21 at 12:51

2 Answers2

1

The restore during the build is not sent to the app service.

Is necessary to add the configuration key SCM_DO_BUILD_DURING_DEPLOYMENT with value: 1

enter image description here

It will install requirements during deployment.

If you need any initialization code like in my example, you can add it in General Settings

enter image description here

Murilo Maciel Curti
  • 2,677
  • 1
  • 21
  • 26
0

Newest

Change target path ,--target="./.python_packages/lib/site-packages" .

- bash: |
   python3.8 -m venv worker_venv
   source worker_venv/bin/activate
   pip3.8 install setuptools
   pip3.8 install --target="./.python_packages/lib/site-packages" -r requirements.txt
   displayName: 'Install Application Dependencies'

You need to install a new Python runtime at the path D:\home via Kudu site extensions.(Windows)

The problems is, azure app service use virtualenv by default, so the requirements.txt package is automaticly installed to python in the virtualenv... so I just edit the deploy.cmd to install requirements to python (extension)

For more details, you can refer Peter Pan's answer in below post.

Why is the azure app service django deploy keep failing?

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • 1
    Unfortunately I am on trying to run on a Linux server. The issue may be the same (I get a notice that the normal site-package is not writable) but I am not sure how to resolve it on as the link seems to be Windows specific. – Adam Tamargo Jan 27 '21 at 02:32
  • 1
    I deployed using your recommendation and still cannot run the installed modules. Now, all my installed packages are in /home/.local/lib/python2.7/site-packages. The directory /home/site/wwwroot/worker_venv/lib/python3.8/site-packages exists but holds none of my installed modules. The issue is no longer that my modules are not available but that the Python 2 .7 is being used when I need 3. It seems to me that this means the venv never starts as it should before the installations take place. – Adam Tamargo Jan 27 '21 at 17:20