ModuleNotFoundError: "No module named <mymodule>", when deploying to Heroku from Django
ModuleNotFoundError: "No module named <mymodule>", when deploying to Heroku from Django
将我的 Django 应用程序部署到 Heroku 时,我收到一个 ModuleNotFoundError,指出“没有名为 'RealisticEstate' 的模块”。 RealisticEstate 是我的 Django 项目的名称。该程序构建没有问题,但是当我尝试部署时出现以下错误:
[2021-05-13 21:35:45 -0400] [15610] [INFO] Starting gunicorn 20.1.0
9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15610] [INFO] Listening at:
http://0.0.0.0:5000 (15610) 9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15610] [INFO] Using worker: sync
9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15613] [INFO] Booting worker with pid: 15613
9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15613] [ERROR] Exception in worker process
9:35:45 PM web.1 | Traceback (most recent call last):
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site- packages/gunicorn/arbiter.py", line 589, in spawn_worker
9:35:45 PM web.1 | worker.init_process()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
9:35:45 PM web.1 | self.load_wsgi()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
9:35:45 PM web.1 | self.wsgi = self.app.wsgi()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
9:35:45 PM web.1 | self.callable = self.load()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
9:35:45 PM web.1 | return self.load_wsgiapp()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
9:35:45 PM web.1 | return util.import_app(self.app_uri)
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
9:35:45 PM web.1 | mod = importlib.import_module(module)
9:35:45 PM web.1 | File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
9:35:45 PM web.1 | return _bootstrap._gcd_import(name[level:], package, level)
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
9:35:45 PM web.1 | ModuleNotFoundError: No module named 'RealisticEstate'
我的Procfile如下:
web: gunicorn RealisticEstate.wsgi
我的 Heroku 项目名为“realisticestate”,但是当我尝试将我的 Procfile 更改为:
web: gunicorn realisticestate.wsgi
它抛出同样的错误。
项目结构如下:
RealisticEstate
|___config
| |___static
| | |___admin
| | |___css
| | |___font
| | |___img
| | |___js
| |___ __init__.py
| |___ asgi.py
| |___ settings.py
| |___ urls.py
| |___ wsgi.py
|
|___mapper
| |___ migrations
| |___ utils
| | |___ __init.py__
| | |___ update_db.py
| |___ __init.py__
| |___ admin.py
| |___ apps.py
| |___ forms.py
| |___ models.py
| |___ tests.py
| |___ urls.py
| |___ views.py
| |___ staticfiles
|
|___ templates
|___ venv
|___ .gitignore
|___ manage.py
|___ models.py
|___ Procfile
|___ requirements.txt
如有任何帮助,我们将不胜感激
只有 git 根目录 (RealisticEstate
) 中的内容才会被推送到 Heroku,而不是目录本身。你的 wsgi 文件是 config/wsgi.py
因此你应该使用:
web: gunicorn config.wsgi
确实需要将 project_name 放入 Procfile,因为包含所有文件夹的文件夹始终与 wsgi.py 所在的文件夹同名 存在。您的 Procfile 应该指向,但在您的情况下,您将其命名为 config 所以应该是:
web: gunicorn config.wsgi
我个人是这样加的:
web: gunicorn config.wsgi --log-file -
将我的 Django 应用程序部署到 Heroku 时,我收到一个 ModuleNotFoundError,指出“没有名为 'RealisticEstate' 的模块”。 RealisticEstate 是我的 Django 项目的名称。该程序构建没有问题,但是当我尝试部署时出现以下错误:
[2021-05-13 21:35:45 -0400] [15610] [INFO] Starting gunicorn 20.1.0
9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15610] [INFO] Listening at:
http://0.0.0.0:5000 (15610) 9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15610] [INFO] Using worker: sync
9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15613] [INFO] Booting worker with pid: 15613
9:35:45 PM web.1 | [2021-05-13 21:35:45 -0400] [15613] [ERROR] Exception in worker process
9:35:45 PM web.1 | Traceback (most recent call last):
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site- packages/gunicorn/arbiter.py", line 589, in spawn_worker
9:35:45 PM web.1 | worker.init_process()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
9:35:45 PM web.1 | self.load_wsgi()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
9:35:45 PM web.1 | self.wsgi = self.app.wsgi()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
9:35:45 PM web.1 | self.callable = self.load()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
9:35:45 PM web.1 | return self.load_wsgiapp()
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
9:35:45 PM web.1 | return util.import_app(self.app_uri)
9:35:45 PM web.1 | File "/Users/<user>/RealisticEstate/venv/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
9:35:45 PM web.1 | mod = importlib.import_module(module)
9:35:45 PM web.1 | File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
9:35:45 PM web.1 | return _bootstrap._gcd_import(name[level:], package, level)
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
9:35:45 PM web.1 | File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
9:35:45 PM web.1 | ModuleNotFoundError: No module named 'RealisticEstate'
我的Procfile如下:
web: gunicorn RealisticEstate.wsgi
我的 Heroku 项目名为“realisticestate”,但是当我尝试将我的 Procfile 更改为:
web: gunicorn realisticestate.wsgi
它抛出同样的错误。
项目结构如下:
RealisticEstate
|___config
| |___static
| | |___admin
| | |___css
| | |___font
| | |___img
| | |___js
| |___ __init__.py
| |___ asgi.py
| |___ settings.py
| |___ urls.py
| |___ wsgi.py
|
|___mapper
| |___ migrations
| |___ utils
| | |___ __init.py__
| | |___ update_db.py
| |___ __init.py__
| |___ admin.py
| |___ apps.py
| |___ forms.py
| |___ models.py
| |___ tests.py
| |___ urls.py
| |___ views.py
| |___ staticfiles
|
|___ templates
|___ venv
|___ .gitignore
|___ manage.py
|___ models.py
|___ Procfile
|___ requirements.txt
如有任何帮助,我们将不胜感激
只有 git 根目录 (RealisticEstate
) 中的内容才会被推送到 Heroku,而不是目录本身。你的 wsgi 文件是 config/wsgi.py
因此你应该使用:
web: gunicorn config.wsgi
确实需要将 project_name 放入 Procfile,因为包含所有文件夹的文件夹始终与 wsgi.py 所在的文件夹同名 存在。您的 Procfile 应该指向,但在您的情况下,您将其命名为 config 所以应该是:
web: gunicorn config.wsgi
我个人是这样加的:
web: gunicorn config.wsgi --log-file -