简体   繁体   中英

ModuleNotFoundError: "No module named <mymodule>", when deploying to Heroku from Django

When deploying my Django app to Heroku, I get a ModuleNotFoundError that states "no module named 'RealisticEstate'". RealisticEstate is the name of my Django project. The program builds no problem, but when I try to deploy I get the following errors:

[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'

My Procfile is as follows:

web: gunicorn RealisticEstate.wsgi

My Heroku project is named "realisticestate", but when I tried changing my Procfile to:

web: gunicorn realisticestate.wsgi

it throws the same error.

Here is the project structure:

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

Any help would be greatly appreciated

Only what's inside the git root directory ( RealisticEstate ) will be pushed to Heroku, not the directory itself. Your wsgi file is then config/wsgi.py therefore you should use:

web: gunicorn config.wsgi

it is true that you need to put project_name in your Procfile, and that because always the folders wraping all the folder have the same name of the folder where wsgi.py exists.wich your Procfile should point to,but in your case you named it config so it should be:

web: gunicorn config.wsgi 

i personally add it like this:

web: gunicorn config.wsgi --log-file -

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM