& quot; ModuleNotFoundError:没有名为' django'&的模块尝试在Azure上部署Django服务器时 [英] "ModuleNotFoundError: No module named 'django'" when trying to deploy Django server on Azure

查看:84
本文介绍了& quot; ModuleNotFoundError:没有名为' django'&的模块尝试在Azure上部署Django服务器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Azure上部署Django网站后,出现错误消息:

  ModuleNotFoundError:没有名为"django"的模块 

我在Django项目的根目录中添加了requirements.txt,是否还有其他内容?我曾尝试从Kudu BASH安装Django,但它卡在清理"上.

这是完整的错误:

要安装其他软件包,例如Django,请使用 pip Frozen>在项目的根目录中创建一个requirements.txt文件.requirements.txt .然后,使用Git部署将项目发布到App Service,该部署会在容器中自动运行 pip install -r requirements.txt 来安装应用程序的依赖项.

因此,可能的原因是 requirements.txt 文件不在部署后的项目或容器的相应路径中,该路径应为/home/site/wwwroot/requirements.txt放在容器或项目的根目录上,例如官方示例 Azure-Samples/djangoapp 在GitHub上.

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.

解决方案

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.

  1. Quickstart: Create a Python app in Azure App Service on Linux
  2. Configure a Linux Python app for Azure App Service

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 runs pip 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.

这篇关于& quot; ModuleNotFoundError:没有名为' django'&的模块尝试在Azure上部署Django服务器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆