简体   繁体   English

如何在 AWS 上修复 Django“ModuleNotFoundError:没有名为‘application’的模块”?

[英]How to fix Django "ModuleNotFoundError: No module named 'application'" on AWS?

I am trying to redeploy a Django web application on AWS.我正在尝试在 AWS 上重新部署 Django web 应用程序。 My elastic beanstalk environment has been red a couple of times.我的 elastic beanstalk 环境已经红了几次。 When I ran eb logs on the cli, I am getting a "ModuleNotFoundError: No module named 'application' error".当我在 cli 上运行 eb logs 时,我收到“ModuleNotFoundError:没有名为‘application’的模块错误”。 I think this has got to do with my wsgi configuration.我认为这与我的 wsgi 配置有关。

I have deployed this web app on AWS before.我之前在 AWS 上部署过这个 web 应用程序。 I messed up when I tried deploying a new version then decided to just start over.当我尝试部署新版本然后决定重新开始时,我搞砸了。 Here is my wsgi.py configuration:这是我的 wsgi.py 配置:

```import os

from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = StaticFilesHandler(get_wsgi_application())```

When I deploy the app, it's giving me a 502: Bad gateway error.当我部署应用程序时,它给我一个 502:网关错误。 Let me know if you would like more info on the issue.如果您想了解有关此问题的更多信息,请告诉我。 Any pointers would be greatly appreciated.任何指针将不胜感激。

By default, Elastic Beanstalk looks for a file named application.py to start your application.默认情况下,Elastic Beanstalk 会查找名为 application.py 的文件来启动您的应用程序。 Because this doesn't exist in the Django project that you've created, you need to make some adjustments to your application's environment.因为这在您创建的 Django 项目中不存在,所以您需要对应用程序的环境进行一些调整。 You also must set environment variables so that your application's modules can be loaded.您还必须设置环境变量,以便可以加载应用程序的模块。

follow these instructions: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-configure-for-eb请按照以下说明操作: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-configure-for-eb

I got this error because in an older version the django.config looked like this:我收到此错误是因为在旧版本中 django.config 看起来像这样:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: ebdjango/wsgi.py

and now it should look like this:现在它应该是这样的:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: ebdjango.wsgi:application

I faced this issue as well.我也遇到了这个问题。 In my case I was getting a 502 nginx error after deploying to AWS EB using eb deploy and my environment had a red flag.在我的例子中,我在使用eb deploy部署到 AWS EB 后收到 502 nginx 错误,我的环境有一个危险信号。

My AWS EB was using Amazon Linux 2 AMI, everything was set correctly BUT after lot of tries and errors I realized my .ebextensions folder was named .ebtextensions .我的 AWS EB 使用的是 Amazon Linux 2 AMI,一切设置正确但经过大量尝试和错误后我意识到我的.ebextensions文件夹被命名为.ebtextensions

I wish EB or django would have indicated on its logs that my folder was nanmed incorrectly.我希望 EB 或 django 会在其日志中指出我的文件夹命名不正确。

I got this error and also spent days trying to solve it.我遇到了这个错误,也花了几天时间试图解决它。 The problem is from the django.config file.问题来自 django.config 文件。

option_settings:
  aws:elasticbeanstalk:container:python:
  WSGIPath: <app name>.wsgi:application

The first value (app name) in the WSGIPath option needs to be the directory that contains the wsgi.py file WSGIPath 选项中的第一个值(应用程序名称)需要是包含 wsgi.py 文件的目录

Check the WSGIPath in elastic beanstalk configuration (Software Category) in the AWS console too.还要检查 AWS 控制台中弹性 beanstalk 配置(软件类别)中的 WSGIPath。

It should be它应该是

<app_name>.wsgi:application

The "ModuleNotFoundError: No module named 'application'" error in Django is typically caused by a problem with your Python import path. Django 中的“ModuleNotFoundError: No module named 'application'”错误通常是由您的 Python 导入路径问题引起的。 Here are some steps you can take to fix this issue on AWS:您可以采取以下步骤在 AWS 上解决此问题:

1)Verify that your Django project's settings.py file has the correct path to your application. Make sure that the path is correct and that the application name is spelled correctly.

2)Check that the application folder is inside your project folder and that the __init__.py file is present in the application folder.

3)Check that the application is correctly included in the INSTALLED_APPS list in your project's settings.py file. Make sure the name of the app is spelled correctly and that it's in the correct case.

4)If you're using a virtual environment, make sure that the virtual environment is activated, and that the required dependencies are installed in it.

5)Make sure that all the dependencies of your application are installed in the correct environment and versions. You can check this by running pip freeze command in the terminal and check the versions of the packages

6)Restart the web server after making any changes.

7)If the problem persists, check the logs of your web server and the output of the Django management commands to see if there are any additional error messages that might provide more information about the cause of the problem.

8)If the problem is still not fixed, you can try creating a new virtual environment, install all the dependencies again and run the project again.

By following these steps, you should be able to resolve the "ModuleNotFoundError: No module named 'application'" error and get your Django application running on AWS.通过执行这些步骤,您应该能够解决“ModuleNotFoundError:没有名为‘application’的模块”错误,并让您的 Django 应用程序在 AWS 上运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:将 Django 应用程序部署到 AWS EB 时没有名为“application”的模块 - ModuleNotFoundError: No module named 'application' when deploying Django app to AWS EB 如何修复 Jupyter notebook 依赖项? ModuleNotFoundError:没有名为“boto3”的模块 - How to fix Jupyter notebook dependancies? ModuleNotFoundError: No module named 'boto3' ModuleNotFoundError:没有名为“psycopg2”的模块 [AWS Glue] - ModuleNotFoundError: No module named 'psycopg2' [AWS Glue] 无法使 airflow AWS 连接工作“ModuleNotFoundError:没有名为‘airflow.providers.amazon’的模块” - Can't get airflow AWS connection to work "ModuleNotFoundError: No module named 'airflow.providers.amazon" Django 'ModuleNotFoundError:部署到 Elastic Beanstalk 时没有名为'blog/wsgi' 的模块,以及'连接到上游时出错' - Django 'ModuleNotFoundError: No module named 'blog/wsgi' when deploying to Elastic Beanstalk, as well as 'Error while connecting to Upstream' ModuleNotFoundError:没有名为“google.rpc.context”的模块 - ModuleNotFoundError: No module named 'google.rpc.context' firebase 和 python:ModuleNotFoundError:没有名为“urllib3”的模块 - firebase and python: ModuleNotFoundError: No module named 'urllib3' ModuleNotFoundError:没有名为“google.cloud.location”的模块 - ModuleNotFoundError: No module named 'google.cloud.location' GCP Composer - ModuleNotFoundError:没有名为“airflow.providers.sftp”的模块 - GCP Composer - ModuleNotFoundError: No module named 'airflow.providers.sftp' ModuleNotFoundError:运行 GCP 数据流作业时没有名为“oracledb”的模块 - ModuleNotFoundError: No module named 'oracledb' when running GCP Dataflow jobs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM