Reputation: 588
After I tried to deploy my Django website on Azure, I got an error saying:
ModuleNotFoundError: No module named 'django'
I added a requirements.txt in the root directory of my Django project, am I missing anything else? I've tried to install Django from Kudu BASH but it gets stuck on "Cleaning Up".
Here is the full error: https://pastebin.com/z5xxqM08
I built the site using Django-2.2 and Python 3.6.8.
Upvotes: 2
Views: 4517
Reputation: 1087
I have the same problem, and think it's a bug:
|WARNING|Missing Django module in requirements.txt
Add Django to your requirements.txt file
I certainly do NOT have Django in my requirements.txt file, but that is by design - I'm using Flask, and it installs and runs just fine - except for this error during build!
Upvotes: 1
Reputation: 87
I was facing same issue though Django was there in requirements, I added setting in configuration section from referring following link and redeployed and it worked. I hope it work for you.
SCM_DO_BUILD_DURING_DEPLOYMENT=true
Refer : Remote build on Linux Section
Upvotes: 0
Reputation: 2078
I had the same problem. requirements.txt
was in my repository, but randomly I started getting the same error ModuleNotFoundError: No module named 'django'
after changing a setting or restarting the service or something. Nothing I could do, change the setting, or reboot repeatedly fixed it. Finally what worked for me was this:
Make a small change to the code and commit it, and push it up to the app service.
This fixed it for me. It has happened a couple times now and every time this solution has worked for me. It seems like the App Service sometimes gets in this state and needs to be jostled with this trick?
Upvotes: 1
Reputation: 24128
Just summarized as an answer for other people. According to your error information, I can see that you tried to deploy your Django app to Azure WebApp on Linux based on Docker. So there are two offical documents will help as below.
The error ModuleNotFoundError: No module named 'django'
indicated that there is not django
package installed on the container of Azure Linux WebApp.
Due to the content of Container characteristics
of #2 document above as below,
To install additional packages, such as Django, create a requirements.txt file in the root of your project using
pip freeze > requirements.txt
. Then, publish your project to App Service using Git deployment, which automatically runspip install -r requirements.txt
in the container to install your app's dependencies.
So the possible reason is the requirements.txt
file not in the corrent path of your project or container after deployed, which path should be /home/site/wwwroot/requirements.txt
on the container or the root of your project like the offical sample Azure-Samples/djangoapp
on GitHub.
Upvotes: 3