[英]Deploying python Django project to Heroku error: ModuleNotFoundError: No module named '<settings.py folder name>'
Update: I made a breakthrough in understanding what my problem is, which I'll state below.更新:我在理解我的问题是什么方面取得了突破,我将在下面 state。
I am attempting to deploy a django project to Heroku and I'm stumped with this error right at the bottom:我正在尝试将 django 项目部署到 Heroku,但我在底部遇到了这个错误:
2022-03-04T03:32:53.360457+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath backend.core backend.core.wsgi --log-file -`
2022-03-04T03:32:55.579764+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-04T03:32:54.908542+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-03-04T03:32:54.908855+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [4] [INFO] Listening at: http://0.0.0.0:39265 (4)
2022-03-04T03:32:54.908899+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [4] [INFO] Using worker: sync
2022-03-04T03:32:54.912389+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [9] [INFO] Booting worker with pid: 9
2022-03-04T03:32:54.974193+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [10] [INFO] Booting worker with pid: 10
2022-03-04T03:32:55.113641+00:00 app[web.1]: [2022-03-04 03:32:55 +0000] [9] [ERROR] Exception in worker process
2022-03-04T03:32:55.113643+00:00 app[web.1]: Traceback (most recent call last):
2022-03-04T03:32:55.113660+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-03-04T03:32:55.113661+00:00 app[web.1]: worker.init_process()
2022-03-04T03:32:55.113661+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-03-04T03:32:55.113661+00:00 app[web.1]: self.load_wsgi()
2022-03-04T03:32:55.113662+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-03-04T03:32:55.113662+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-03-04T03:32:55.113662+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-03-04T03:32:55.113663+00:00 app[web.1]: self.callable = self.load()
2022-03-04T03:32:55.113663+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-03-04T03:32:55.113663+00:00 app[web.1]: return self.load_wsgiapp()
2022-03-04T03:32:55.113663+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-03-04T03:32:55.113664+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-03-04T03:32:55.113664+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
2022-03-04T03:32:55.113664+00:00 app[web.1]: mod = importlib.import_module(module)
2022-03-04T03:32:55.113665+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-03-04T03:32:55.113665+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-03-04T03:32:55.113665+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-03-04T03:32:55.113667+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-03-04T03:32:55.113667+00:00 app[web.1]: File "/app/backend/core/wsgi.py", line 16, in <module>
2022-03-04T03:32:55.113667+00:00 app[web.1]: application = get_wsgi_application()
2022-03-04T03:32:55.113667+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2022-03-04T03:32:55.113668+00:00 app[web.1]: django.setup(set_prefix=False)
2022-03-04T03:32:55.113668+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/__init__.py", line 19, in setup
2022-03-04T03:32:55.113668+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2022-03-04T03:32:55.113668+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 87, in __getattr__
2022-03-04T03:32:55.113668+00:00 app[web.1]: self._setup(name)
2022-03-04T03:32:55.113669+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 74, in _setup
2022-03-04T03:32:55.113669+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2022-03-04T03:32:55.113669+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 183, in __init__
2022-03-04T03:32:55.113669+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2022-03-04T03:32:55.113670+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-03-04T03:32:55.113670+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-03-04T03:32:55.113670+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-03-04T03:32:55.113670+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
2022-03-04T03:32:55.113671+00:00 app[web.1]: ModuleNotFoundError: No module named 'core'
2022-03-04T03:32:55.113893+00:00 app[web.1]: [2022-03-04 03:32:55 +0000] [9] [INFO] Worker exiting (pid: 9)
2022-03-04T03:32:55.148185+00:00 app[web.1]: [2022-03-04 03:32:55 +0000] [10] [ERROR] Exception in worker process
In attempt to provide some information, inside my procfile试图在我的 procfile 中提供一些信息
web: gunicorn --pythonpath backend.core backend.core.wsgi --log-file -
release: python backend.manage.py makemigrations - - no-input
Inside requirements.txt内部需求.txt
asgiref==3.5.0
attrs==21.4.0
beautifulsoup4==4.10.0
bs4==0.0.1
certifi==2021.10.8
charset-normalizer==2.0.12
Django==4.0.3
django-core==1.4.1
django-cors-headers==3.11.0
django-filter==21.1
djangorestframework==3.13.1
gunicorn==20.1.0
idna==3.3
jsonlines==3.0.0
lxml==4.8.0
pytz==2021.3
requests==2.27.1
soupsieve==2.3.1
sqlparse==0.4.2
urllib3==1.26.8
virtualenv-tools3==2.0.5
whitenoise==6.0.0
And I have my project set up as我将我的项目设置为
FE_APP/
runtime.txt
requirements.txt
Procfile
backend/
scraper.py
Under FE_APP/backend/
在
FE_APP/backend/
api/
core/
static/
db.sqlite3
manage.py
and in FE_APP/backend/core/
在
FE_APP/backend/core/
__init__.py
errorlog
settings.py
urls.py
wsgi.py
In FE_APP/backend/api/
, I have my views.py
that does import from core.settings a couple variables.在
FE_APP/backend/api/
中,我的views.py
确实从 core.settings 导入了几个变量。
from core.settings import REALMS, GAME_TITLES
But I doubt that's a concern for why this deployment is bugging out on me.但我怀疑这是否是我对这种部署产生干扰的原因。 I can deploy on my local machine just fine but heroku keeps giving me this error.
我可以很好地部署在我的本地机器上,但 heroku 一直给我这个错误。 I feel like I'm so close to deploying, what is going on?
我觉得我离部署很近了,这是怎么回事?
March 7 update EDIT: I initially had the folder that contained settings.py and wsgi.py named 'core' and I recently changed it to 'feh' following this tutorial here . 3 月 7 日更新编辑:我最初将包含 settings.py 和 wsgi.py 的文件夹命名为“core”,最近我按照这里的教程将其更改为“feh”。 Now when I run the
heroku local
command on terminal, I get the error现在,当我在终端上运行
heroku local
命令时,出现错误
ModuleNotFoundError: No module named 'feh'
Among other junk, leading me to believe there's no conflict between any django core module name conflicts with the folder.在其他垃圾中,让我相信任何 django 核心模块名称与文件夹冲突之间没有冲突。 I don't know how to beat this, but I'm making progress at least.
我不知道如何战胜它,但至少我正在取得进步。
While I still haven't fully solved deployment as I still have another obstacle to figure out (which I will probably make another post for), I think I solved this one by adding to my wsgi.py file the whitenoise module and implementation below:虽然我还没有完全解决部署问题,因为我还有另一个障碍需要解决(我可能会为此发表另一篇文章),但我想我通过在我的 wsgi.py 文件中添加 whitenoise 模块和下面的实现来解决这个问题:
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise import WhiteNoise
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'feh.settings')
application = get_wsgi_application()
application = WhiteNoise(application)
EDIT: I also had another error that caused a heroku deployment failure where it could not find my manage.py file.编辑:我还有另一个错误导致 heroku 部署失败,它找不到我的 manage.py 文件。 this was caused by my Procfile not being set up properly,
这是由于我的 Procfile 设置不正确造成的,
Procfile
needed to be set up as so. Procfile
需要这样设置。
web: gunicorn --pythonpath backend feh.wsgi --log-file -
release: python backend/manage.py makemigrations --no-input
backend is the directory of the django project but it's not the root directory of project to be deployed, hence --pythonpath is needed to specify the django project directory. backend为django项目目录,但不是待部署项目的根目录,因此需要--pythonpath指定django项目目录。 And I suppose the space in my --no-input flag also caused errors.
而且我想我的 --no-input 标志中的空格也会导致错误。 Thank you Chris .
谢谢克里斯。 After these and perhaps working some magic with gunicorn and whitenoise and the django-heroku modules (can't remember if this was before or after, sorry), I got it to work.
在这些之后,也许使用 gunicorn 和 whitenoise 以及 django-heroku 模块(不记得这是之前还是之后,对不起),我开始工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.