Heroku gunicorn 部署错误:NoModuleNameError
Posted
技术标签:
【中文标题】Heroku gunicorn 部署错误:NoModuleNameError【英文标题】:Heroku gunicorn deploy error: NoModuleNameError 【发布时间】:2020-05-12 19:22:51 【问题描述】:可能有点超出我的深度,我已经彻底阅读了 heroku 文档,但仍然不太了解应该如何设置 Procfile。尝试部署 heroku ($ heroku open
),会出现以下错误日志:
2020-01-27T11:39:57.597570+00:00 app[web.1]: backlog: 2048
2020-01-27T11:39:57.597572+00:00 app[web.1]: workers: 1
2020-01-27T11:39:57.597590+00:00 app[web.1]: worker_class: sync
2020-01-27T11:39:57.597592+00:00 app[web.1]: threads: 1
2020-01-27T11:39:57.597594+00:00 app[web.1]: worker_connections: 1000
2020-01-27T11:39:57.597596+00:00 app[web.1]: max_requests: 0
2020-01-27T11:39:57.597598+00:00 app[web.1]: max_requests_jitter: 0
2020-01-27T11:39:57.597600+00:00 app[web.1]: timeout: 30
2020-01-27T11:39:57.597602+00:00 app[web.1]: graceful_timeout: 30
2020-01-27T11:39:57.597604+00:00 app[web.1]: keepalive: 2
2020-01-27T11:39:57.597606+00:00 app[web.1]: limit_request_line: 4094
2020-01-27T11:39:57.597608+00:00 app[web.1]: limit_request_fields: 100
2020-01-27T11:39:57.597610+00:00 app[web.1]: limit_request_field_size: 8190
2020-01-27T11:39:57.597612+00:00 app[web.1]: reload: False
2020-01-27T11:39:57.597614+00:00 app[web.1]: reload_engine: auto
2020-01-27T11:39:57.597615+00:00 app[web.1]: spew: False
2020-01-27T11:39:57.597617+00:00 app[web.1]: check_config: False
2020-01-27T11:39:57.597619+00:00 app[web.1]: preload_app: True
2020-01-27T11:39:57.597621+00:00 app[web.1]: sendfile: None
2020-01-27T11:39:57.597623+00:00 app[web.1]: chdir: /app
2020-01-27T11:39:57.597625+00:00 app[web.1]: daemon: False
2020-01-27T11:39:57.597627+00:00 app[web.1]: raw_env: []
2020-01-27T11:39:57.597629+00:00 app[web.1]: pidfile: None
2020-01-27T11:39:57.597630+00:00 app[web.1]: worker_tmp_dir: None
2020-01-27T11:39:57.597632+00:00 app[web.1]: user: 52893
2020-01-27T11:39:57.597634+00:00 app[web.1]: group: 52893
2020-01-27T11:39:57.597636+00:00 app[web.1]: umask: 0
2020-01-27T11:39:57.597638+00:00 app[web.1]: initgroups: False
2020-01-27T11:39:57.597640+00:00 app[web.1]: tmp_upload_dir: None
2020-01-27T11:39:57.597642+00:00 app[web.1]: secure_scheme_headers: 'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'
2020-01-27T11:39:57.597645+00:00 app[web.1]: forwarded_allow_ips: ['*']
2020-01-27T11:39:57.597646+00:00 app[web.1]: accesslog: -
2020-01-27T11:39:57.597648+00:00 app[web.1]: access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
2020-01-27T11:39:57.597650+00:00 app[web.1]: errorlog: -
2020-01-27T11:39:57.597652+00:00 app[web.1]: loglevel: debug
2020-01-27T11:39:57.597654+00:00 app[web.1]: capture_output: False
2020-01-27T11:39:57.597656+00:00 app[web.1]: logger_class: gunicorn.glogging.Logger
2020-01-27T11:39:57.597658+00:00 app[web.1]: logconfig: None
2020-01-27T11:39:57.597660+00:00 app[web.1]: syslog_addr: udp://localhost:514
2020-01-27T11:39:57.597662+00:00 app[web.1]: syslog: False
2020-01-27T11:39:57.597665+00:00 app[web.1]: syslog_prefix: None
2020-01-27T11:39:57.597667+00:00 app[web.1]: syslog_facility: user
2020-01-27T11:39:57.597669+00:00 app[web.1]: enable_stdio_inheritance: False
2020-01-27T11:39:57.597671+00:00 app[web.1]: statsd_host: None
2020-01-27T11:39:57.597673+00:00 app[web.1]: statsd_prefix:
2020-01-27T11:39:57.597674+00:00 app[web.1]: proc_name: None
2020-01-27T11:39:57.597677+00:00 app[web.1]: default_proc_name: grad.wsgi:application
2020-01-27T11:39:57.597679+00:00 app[web.1]: pythonpath: None
2020-01-27T11:39:57.597681+00:00 app[web.1]: paste: None
2020-01-27T11:39:57.597683+00:00 app[web.1]: on_starting: <function OnStarting.on_starting at 0x7fbdff281ae8>
2020-01-27T11:39:57.597685+00:00 app[web.1]: on_reload: <function OnReload.on_reload at 0x7fbdff281c80>
2020-01-27T11:39:57.597687+00:00 app[web.1]: when_ready: <function WhenReady.when_ready at 0x7fbdff281e18>
2020-01-27T11:39:57.597689+00:00 app[web.1]: pre_fork: <function Prefork.pre_fork at 0x7fbdff28b048>
2020-01-27T11:39:57.597691+00:00 app[web.1]: post_fork: <function Postfork.post_fork at 0x7fbdff28b1e0>
2020-01-27T11:39:57.597693+00:00 app[web.1]: post_worker_init: <function PostWorkerInit.post_worker_init at 0x7fbdff28b378>
2020-01-27T11:39:57.597695+00:00 app[web.1]: worker_int: <function WorkerInt.worker_int at 0x7fbdff28b510>
2020-01-27T11:39:57.597697+00:00 app[web.1]: worker_abort: <function WorkerAbort.worker_abort at 0x7fbdff28b6a8>
2020-01-27T11:39:57.597699+00:00 app[web.1]: pre_exec: <function PreExec.pre_exec at 0x7fbdff28b840>
2020-01-27T11:39:57.597700+00:00 app[web.1]: pre_request: <function PreRequest.pre_request at 0x7fbdff28b9d8>
2020-01-27T11:39:57.597702+00:00 app[web.1]: post_request: <function PostRequest.post_request at 0x7fbdff28bae8>
2020-01-27T11:39:57.597704+00:00 app[web.1]: child_exit: <function ChildExit.child_exit at 0x7fbdff28bc80>
2020-01-27T11:39:57.597706+00:00 app[web.1]: worker_exit: <function WorkerExit.worker_exit at 0x7fbdff28be18>
2020-01-27T11:39:57.597708+00:00 app[web.1]: nworkers_changed: <function NumWorkersChanged.nworkers_changed at 0x7fbdff291048>
2020-01-27T11:39:57.597710+00:00 app[web.1]: on_exit: <function OnExit.on_exit at 0x7fbdff2911e0>
2020-01-27T11:39:57.597712+00:00 app[web.1]: proxy_protocol: False
2020-01-27T11:39:57.597714+00:00 app[web.1]: proxy_allow_ips: ['127.0.0.1']
2020-01-27T11:39:57.597716+00:00 app[web.1]: keyfile: None
2020-01-27T11:39:57.597718+00:00 app[web.1]: certfile: None
2020-01-27T11:39:57.597720+00:00 app[web.1]: ssl_version: 2
2020-01-27T11:39:57.597722+00:00 app[web.1]: cert_reqs: 0
2020-01-27T11:39:57.597724+00:00 app[web.1]: ca_certs: None
2020-01-27T11:39:57.597726+00:00 app[web.1]: suppress_ragged_eofs: True
2020-01-27T11:39:57.597728+00:00 app[web.1]: do_handshake_on_connect: False
2020-01-27T11:39:57.597730+00:00 app[web.1]: ciphers: TLSv1
2020-01-27T11:39:57.597736+00:00 app[web.1]: raw_paste_global_conf: []
2020-01-27T11:39:57.597990+00:00 app[web.1]: Traceback (most recent call last):
2020-01-27T11:39:57.597998+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2020-01-27T11:39:57.598184+00:00 app[web.1]: sys.exit(run())
2020-01-27T11:39:57.598190+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2020-01-27T11:39:57.598330+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-01-27T11:39:57.598336+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 203, in run
2020-01-27T11:39:57.598498+00:00 app[web.1]: super(Application, self).run()
2020-01-27T11:39:57.598504+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2020-01-27T11:39:57.598635+00:00 app[web.1]: Arbiter(self).run()
2020-01-27T11:39:57.598641+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 60, in __init__
2020-01-27T11:39:57.598774+00:00 app[web.1]: self.setup(app)
2020-01-27T11:39:57.598780+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 120, in setup
2020-01-27T11:39:57.598919+00:00 app[web.1]: self.app.wsgi()
2020-01-27T11:39:57.598924+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-01-27T11:39:57.599052+00:00 app[web.1]: self.callable = self.load()
2020-01-27T11:39:57.599058+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2020-01-27T11:39:57.599182+00:00 app[web.1]: return self.load_wsgiapp()
2020-01-27T11:39:57.599187+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2020-01-27T11:39:57.599313+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-01-27T11:39:57.599319+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
2020-01-27T11:39:57.599526+00:00 app[web.1]: __import__(module)
2020-01-27T11:39:57.599554+00:00 app[web.1]: ModuleNotFoundError: No module named 'grad'
2020-01-27T11:40:01.000000+00:00 app[api]: Build succeeded
2020-01-27T11:40:13.471679+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=graduateproofreading.herokuapp.com request_id=013c7a9d-29af-445d-8417-3ca07ceeb6bb fwd="86.132.11.140" dyno= connect= service= status=503 bytes= protocol=https
2020-01-27T11:40:13.643175+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=graduateproofreading.herokuapp.com request_id=9ba58cb3-7954-4c37-8d4a-23112dabe8f5 fwd="86.132.11.140" dyno= connect= service= status=503 bytes= protocol=https
我猜这就是那一堆令人困惑的代码2020-01-27T11:39:57.599554+00:00 app[web.1]: ModuleNotFoundError: No module named 'grad'
中的操作线,但我显然不是专家...
我的 Procfile 看起来像这样:
web: gunicorn grad.wsgi:application --log-file - --log-level debug --preload --workers 1
grad.wsgi 看起来像这样:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "grad.settings")
application = get_wsgi_application()
我的文件夹结构(如果需要):
├── CNAME
├── get-pip.py
├── gpproject
│ ├── db.sqlite3
│ ├── gp.sublime-project
│ ├── gp.sublime-workspace
│ ├── grad
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-35.pyc
│ │ │ ├── settings.cpython-35.pyc
│ │ │ ├── urls.cpython-35.pyc
│ │ │ └── wsgi.cpython-35.pyc
│ │ ├── settings.py
│ │ ├── static
│ │ │ ├── office.jpeg
│ │ │ └── pics
│ │ │ └── office.jpeg
│ │ ├── urls.py
│ │ ├── views.py
│ │ └── wsgi.py
│ ├── jobboard
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ │ ├── 0001_initial.py
│ │ │ ├── 0002_auto_20180716_1122.py
│ │ │ └── __init__.py
│ │ ├── models.py
│ │ ├── tests.py
│ │ └── views.py
│ ├── login
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ │ ├── 0001_initial.py
│ │ │ ├── __init__.py
│ │ │ └── __pycache__
│ │ │ ├── 0001_initial.cpython-35.pyc
│ │ │ └── __init__.cpython-35.pyc
│ │ ├── models.py
│ │ ├── __pycache__
│ │ │ ├── admin.cpython-35.pyc
│ │ │ ├── apps.cpython-35.pyc
│ │ │ ├── __init__.cpython-35.pyc
│ │ │ ├── models.cpython-35.pyc
│ │ │ ├── urls.cpython-35.pyc
│ │ │ └── views.cpython-35.pyc
│ │ ├── static
│ │ │ └── pics
│ │ │ └── office.jpeg
│ │ ├── templates
│ │ │ ├── login
│ │ │ │ └── office.jpeg
│ │ │ ├── loginbutton.html
│ │ │ ├── logoutbutton.html
│ │ │ ├── navbar.html
│ │ │ ├── registration
│ │ │ │ ├── login.html
│ │ │ │ ├── logintut.html
│ │ │ │ ├── password_reset_complete.html
│ │ │ │ ├── password_reset_confirm.html
│ │ │ │ ├── password_reset_done.html
│ │ │ │ ├── password_reset_email.html
│ │ │ │ └── password_reset_form.html
│ │ │ └── signup.html
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── manage.py
│ ├── oldbackupdb.sqlite3
│ ├── staticfiles
│ ├── templates
│ │ ├── base.html
│ │ ├── footer.html
│ │ ├── Header.html
│ │ ├── index2.html
│ │ ├── index.html
│ │ ├── jobpost.html
│ │ ├── jobs.html
│ │ ├── navbar.html
│ │ ├── oldHeader.html
│ │ ├── sidenav.html
│ │ ├── signup.html
│ │ └── userdropdown.html
│ ├── universities.xcf
│ └── users
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-35.pyc
│ │ └── __init__.cpython-35.pyc
│ ├── models.py
│ ├── __pycache__
│ │ ├── admin.cpython-35.pyc
│ │ ├── forms.cpython-35.pyc
│ │ ├── __init__.cpython-35.pyc
│ │ ├── models.cpython-35.pyc
│ │ ├── urls.cpython-35.pyc
│ │ └── views.cpython-35.pyc
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── gradproofworkspace.code-workspace
├── index-1.html
├── index1.html
├── index-2.html
├── office.jpeg
├── Pipfile
├── Pipfile.lock
├── Procfile
├── README.md
├── requirements.txt
└── runtime.txt
我想不出还需要什么,但请索取更多信息。任何关于 Procfile 工作原理的明确和愚蠢的建议都会很棒,在此先感谢。
【问题讨论】:
【参考方案1】:您正确识别出错误消息中的关键行是ModuleNotFoundError
。
2020-01-27T11:39:57.599554+00:00 app[web.1]: ModuleNotFoundError: No module named 'grad'
问题是您的 Django 项目目录(包含 manage.py
的目录)不在项目根目录中,而是在 gpproject
目录中。
因此,您需要将该目录添加到带有--python
标志的Python 路径中,以便可以导入其中的grad
模块。
web: gunicorn grad.wsgi:application --python gpproject --log-file - --log-level debug --preload --workers 1
【讨论】:
谢谢!经过大量的网络搜索,我终于找到了对我有帮助的答案。【参考方案2】:尝试将您的 Procfile 更新为:
web: gunicorn grad.wsgi --log-file - --log-level debug --preload --workers 1
我有一些使用类似设置的 Heroku-Django 应用程序。让我知道它是否适合您?
【讨论】:
我没有尝试这个,因为 Alasdair 提供的答案有效,但还是谢谢以上是关于Heroku gunicorn 部署错误:NoModuleNameError的主要内容,如果未能解决你的问题,请参考以下文章
ModuleNotFound 错误尝试在 Heroku 中打开 Django 应用程序 - gunicorn 设置问题?