ModuleNotFoundError:没有名为“应用程序”的模块 [将 Django 部署到 AWS]
Posted
技术标签:
【中文标题】ModuleNotFoundError:没有名为“应用程序”的模块 [将 Django 部署到 AWS]【英文标题】:ModuleNotFoundError: No module named 'application' [Deploying Django to AWS] 【发布时间】:2021-11-18 00:28:01 【问题描述】:我一直在尝试从 AWS 在 ElasticBeanstalk 上部署 Django 应用程序。
我已经关注 this 教程大概 6 或 7 次了。
尝试以任何一种方式从 Linux 和 Windows 机器部署,我最终得到:
ModuleNotFoundError: No module named 'application'
或 web: Failed to find attribute 'application' in 'application'.
其他文件是空白的,因为我已经尝试过我的一个项目,现在我正在尝试一个空白的。
django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: c2exchange.wsgi:application
wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'c2exchange.settings')
application = get_wsgi_application()
这些是我的文件:
日志:
----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Sep 24 22:23:48 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Sep 24 22:23:48 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Sep 24 22:23:48 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Sep 24 22:23:48 ip-172-31-33-134 web: ModuleNotFoundError: No module named 'application'
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1250] [INFO] Worker exiting (pid: 1250)
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1244] [INFO] Shutting down: Master
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1244] [INFO] Reason: Worker failed to boot.
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1258] [INFO] Starting gunicorn 20.1.0
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1258] [INFO] Using worker: gthread
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1264] [INFO] Booting worker with pid: 1264
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1264] [ERROR] Exception in worker process
Sep 24 22:23:48 ip-172-31-33-134 web: Traceback (most recent call last):
Sep 24 22:23:48 ip-172-31-33-134 web: worker.init_process()
Sep 24 22:23:48 ip-172-31-33-134 web: super().init_process()
Sep 24 22:23:48 ip-172-31-33-134 web: self.load_wsgi()
Sep 24 22:23:48 ip-172-31-33-134 web: self.wsgi = self.app.wsgi()
Sep 24 22:23:48 ip-172-31-33-134 web: self.callable = self.load()
Sep 24 22:23:48 ip-172-31-33-134 web: return self.load_wsgiapp()
Sep 24 22:23:48 ip-172-31-33-134 web: return util.import_app(self.app_uri)
Sep 24 22:23:48 ip-172-31-33-134 web: mod = importlib.import_module(module)
Sep 24 22:23:48 ip-172-31-33-134 web: File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
Sep 24 22:23:48 ip-172-31-33-134 web: return _bootstrap._gcd_import(name[level:], package, level)
Sep 24 22:23:48 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Sep 24 22:23:48 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Sep 24 22:23:48 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Sep 24 22:23:48 ip-172-31-33-134 web: ModuleNotFoundError: No module named 'application'
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1264] [INFO] Worker exiting (pid: 1264)
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1258] [INFO] Shutting down: Master
Sep 24 22:23:48 ip-172-31-33-134 web: [2021-09-24 22:23:48 +0000] [1258] [INFO] Reason: Worker failed to boot.
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1272] [INFO] Starting gunicorn 20.1.0
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1272] [INFO] Using worker: gthread
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1278] [INFO] Booting worker with pid: 1278
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1278] [ERROR] Exception in worker process
Sep 24 22:23:49 ip-172-31-33-134 web: Traceback (most recent call last):
Sep 24 22:23:49 ip-172-31-33-134 web: worker.init_process()
Sep 24 22:23:49 ip-172-31-33-134 web: super().init_process()
Sep 24 22:23:49 ip-172-31-33-134 web: self.load_wsgi()
Sep 24 22:23:49 ip-172-31-33-134 web: self.wsgi = self.app.wsgi()
Sep 24 22:23:49 ip-172-31-33-134 web: self.callable = self.load()
Sep 24 22:23:49 ip-172-31-33-134 web: return self.load_wsgiapp()
Sep 24 22:23:49 ip-172-31-33-134 web: return util.import_app(self.app_uri)
Sep 24 22:23:49 ip-172-31-33-134 web: mod = importlib.import_module(module)
Sep 24 22:23:49 ip-172-31-33-134 web: File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
Sep 24 22:23:49 ip-172-31-33-134 web: return _bootstrap._gcd_import(name[level:], package, level)
Sep 24 22:23:49 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Sep 24 22:23:49 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Sep 24 22:23:49 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Sep 24 22:23:49 ip-172-31-33-134 web: ModuleNotFoundError: No module named 'application'
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1278] [INFO] Worker exiting (pid: 1278)
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1272] [INFO] Shutting down: Master
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1272] [INFO] Reason: Worker failed to boot.
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1286] [INFO] Starting gunicorn 20.1.0
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1286] [INFO] Using worker: gthread
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1292] [INFO] Booting worker with pid: 1292
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1292] [ERROR] Exception in worker process
Sep 24 22:23:49 ip-172-31-33-134 web: Traceback (most recent call last):
Sep 24 22:23:49 ip-172-31-33-134 web: worker.init_process()
Sep 24 22:23:49 ip-172-31-33-134 web: super().init_process()
Sep 24 22:23:49 ip-172-31-33-134 web: self.load_wsgi()
Sep 24 22:23:49 ip-172-31-33-134 web: self.wsgi = self.app.wsgi()
Sep 24 22:23:49 ip-172-31-33-134 web: self.callable = self.load()
Sep 24 22:23:49 ip-172-31-33-134 web: return self.load_wsgiapp()
Sep 24 22:23:49 ip-172-31-33-134 web: return util.import_app(self.app_uri)
Sep 24 22:23:49 ip-172-31-33-134 web: mod = importlib.import_module(module)
Sep 24 22:23:49 ip-172-31-33-134 web: File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
Sep 24 22:23:49 ip-172-31-33-134 web: return _bootstrap._gcd_import(name[level:], package, level)
Sep 24 22:23:49 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Sep 24 22:23:49 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Sep 24 22:23:49 ip-172-31-33-134 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Sep 24 22:23:49 ip-172-31-33-134 web: ModuleNotFoundError: No module named 'application'
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1292] [INFO] Worker exiting (pid: 1292)
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1286] [INFO] Shutting down: Master
Sep 24 22:23:49 ip-172-31-33-134 web: [2021-09-24 22:23:49 +0000] [1286] [INFO] Reason: Worker failed to boot.
----------------------------------------
/var/log/nginx/access.log
----------------------------------------
172.31.37.198 - - [24/Sep/2021:18:12:26 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://c2deving.eba-zv3cph3u.sa-east-1.elasticbeanstalk.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/93.0.4577.82 Safari/537.36" "177.142.87.161"
172.31.8.207 - - [24/Sep/2021:18:15:30 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://c2deving.eba-zv3cph3u.sa-east-1.elasticbeanstalk.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36" "177.142.87.161"
172.31.37.198 - - [24/Sep/2021:19:08:15 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "htt
【问题讨论】:
您使用的是 Amazon Linux 1 还是 Amazon Linux 2?不幸的是,配置文件需要根据您使用的版本而有所不同。 Amazon Linux 2,我错过了一些文件吗? 可以显示eb logs
的内容吗?
你提交了所有这些文件吗?如果你已经为你的项目初始化了 git,它会部署当前分支的最新提交 - docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html
我以前试过,昨天也试过,还是一样的问题。
【参考方案1】:
试试 如果您使用的是 mac,请确保您正在压缩文件, 不是***的。
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html
【讨论】:
以上是关于ModuleNotFoundError:没有名为“应用程序”的模块 [将 Django 部署到 AWS]的主要内容,如果未能解决你的问题,请参考以下文章
ModuleNotFoundError:没有名为“dataviz”的模块
ModuleNotFoundError:没有名为“numpy”的模块
错误:ModuleNotFoundError:没有名为“图像”的模块
ModuleNotFoundError:没有名为“knox”的模块