Heroku gunicorn deploy error: NoModuleNameError

可紊 提交于 2020-06-23 11:22:23

问题


possibly a little out my depth here, I've read the heroku docs thoroughly and still don't quite understand how the Procfile should be set up. Trying to deploy heroku ($ heroku open), gives this error log:

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

I guess that this is the operative line in that mass of confusing code 2020-01-27T11:39:57.599554+00:00 app[web.1]: ModuleNotFoundError: No module named 'grad', but I'm quite obviously no expert...

My Procfile looks like this:

web: gunicorn grad.wsgi:application --log-file - --log-level debug --preload --workers 1

grad.wsgi looks like this:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "grad.settings")

application = get_wsgi_application()

My folder structure (if needed):

├── 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

I can't think what else might be needed but please request any further info. Any clear and idiot-proof advice on how Procfile works would be great, thanks in advance.


回答1:


You correctly identified that the key line in the error message is the ModuleNotFoundError.

2020-01-27T11:39:57.599554+00:00 app[web.1]: ModuleNotFoundError: No module named 'grad'

The problem is that your Django project directory (the one containing manage.py) isn't in the project root, it's in the gpproject directory.

Therefore you need to add that directory to the Python path with the --python flag, so that the grad module inside it can be imported.

web: gunicorn grad.wsgi:application --python gpproject --log-file - --log-level debug --preload --workers 1



回答2:


try updating your Procfile to read as:

web: gunicorn grad.wsgi --log-file - --log-level debug --preload --workers 1

I have a few Heroku-Django apps that works with a similar setup. Let me know if it works for you?



来源:https://stackoverflow.com/questions/59930777/heroku-gunicorn-deploy-error-nomodulenameerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!