Django / Heroku Deploying - ModuleNotFoundError: "No module named 'django'"
Django / Heroku Deploying - ModuleNotFoundError: "No module named 'django'"
如果我将我的 Django 项目部署到 Heroku,我会得到 ModuleNotFoundError: No module named 'django'
。有谁知道这是为什么?
附件为打开后的完整日志文件。找了好几个小时都没解决...
2021-04-24T21:54:55.188701+00:00 heroku[web.1]: State changed from crashed to starting
2021-04-24T21:54:59.835950+00:00 heroku[web.1]: Starting process with command `gunicorn MPLoadManagement.wsgi --log-file -`
2021-04-24T21:55:02.907766+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Starting gunicorn 19.9.0
2021-04-24T21:55:02.908183+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Listening at: http://0.0.0.0:3028 (4)
2021-04-24T21:55:02.908277+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Using worker: sync
2021-04-24T21:55:02.909677+00:00 app[web.1]: /app/.heroku/python/lib/python3.9/os.py:1023: RuntimeWarning: line buffering (buffering=1) isnt supported in binary mode, the default buffer size will be used
2021-04-24T21:55:02.909678+00:00 app[web.1]: return io.open(fd, *args, **kwargs)
2021-04-24T21:55:02.912935+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [7] [INFO] Booting worker with pid: 7
2021-04-24T21:55:02.919805+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [7] [ERROR] Exception in worker process
2021-04-24T21:55:02.919807+00:00 app[web.1]: Traceback (most recent call last):
2021-04-24T21:55:02.919817+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-04-24T21:55:02.919818+00:00 app[web.1]: worker.init_process()
2021-04-24T21:55:02.919818+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 129, in init_process
2021-04-24T21:55:02.919818+00:00 app[web.1]: self.load_wsgi()
2021-04-24T21:55:02.919819+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2021-04-24T21:55:02.919819+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-04-24T21:55:02.919820+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-04-24T21:55:02.919820+00:00 app[web.1]: self.callable = self.load()
2021-04-24T21:55:02.919820+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2021-04-24T21:55:02.919821+00:00 app[web.1]: return self.load_wsgiapp()
2021-04-24T21:55:02.919821+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2021-04-24T21:55:02.919821+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-04-24T21:55:02.919822+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 350, in import_app
2021-04-24T21:55:02.919822+00:00 app[web.1]: __import__(module)
2021-04-24T21:55:02.919823+00:00 app[web.1]: File "/app/MPLoadManagement/wsgi.py", line 12, in <module>
2021-04-24T21:55:02.919823+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-04-24T21:55:02.919823+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-04-24T21:55:02.919969+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-04-24T21:55:02.953092+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Shutting down: Master
2021-04-24T21:55:02.953195+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-04-24T21:55:03.019883+00:00 heroku[web.1]: Process exited with status 3
2021-04-24T21:55:03.124137+00:00 heroku[web.1]: State changed from starting to crashed
Requirements.txt
appdirs==1.4.4
asgiref==3.3.1
astroid==2.5.2
beautifulsoup4==4.9.3
certifi==2020.12.5
distlib==0.3.1
dj-database-url==0.5.0
Django==3.1.7
django-autoslug==1.9.8
django-bootstrap-modal-forms==2.1.0
django-bootstrap4==2.3.1
django-crispy-forms==1.11.2
django-heroku==0.0.0
django-widget-tweaks==1.4.8
filelock==3.0.12
gunicorn==19.9.0
isort==5.8.0
lazy-object-proxy==1.6.0
mccabe==0.6.1
pipenv==2020.11.15
psycopg2-binary==2.8.6
pylint==2.7.4
pytz==2021.1
six==1.15.0
soupsieve==2.2.1
sqlparse==0.4.1
toml==0.10.2
virtualenv==20.4.4
virtualenv-clone==0.5.4
whitenoise==5.2.0
wrapt==1.12.1
在您的需求文件中,将 psycopg2-binary
更改为 psycopg2
您正在安装 django-heroku==0.0.0
这是您真正想要的吗?
我已经向 Heroku 部署了 5 个以上的项目,我从来没有遇到过这样的错误,但是从错误消息中可以明显看出 Django 可能没有安装,重新部署你的项目,看看它是否有效
我现在能够解决问题了。这是因为我没有创建生产部署所需的 static_root 和 staticfiles_storage 文件夹
如果我将我的 Django 项目部署到 Heroku,我会得到 ModuleNotFoundError: No module named 'django'
。有谁知道这是为什么?
附件为打开后的完整日志文件。找了好几个小时都没解决...
2021-04-24T21:54:55.188701+00:00 heroku[web.1]: State changed from crashed to starting
2021-04-24T21:54:59.835950+00:00 heroku[web.1]: Starting process with command `gunicorn MPLoadManagement.wsgi --log-file -`
2021-04-24T21:55:02.907766+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Starting gunicorn 19.9.0
2021-04-24T21:55:02.908183+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Listening at: http://0.0.0.0:3028 (4)
2021-04-24T21:55:02.908277+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Using worker: sync
2021-04-24T21:55:02.909677+00:00 app[web.1]: /app/.heroku/python/lib/python3.9/os.py:1023: RuntimeWarning: line buffering (buffering=1) isnt supported in binary mode, the default buffer size will be used
2021-04-24T21:55:02.909678+00:00 app[web.1]: return io.open(fd, *args, **kwargs)
2021-04-24T21:55:02.912935+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [7] [INFO] Booting worker with pid: 7
2021-04-24T21:55:02.919805+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [7] [ERROR] Exception in worker process
2021-04-24T21:55:02.919807+00:00 app[web.1]: Traceback (most recent call last):
2021-04-24T21:55:02.919817+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-04-24T21:55:02.919818+00:00 app[web.1]: worker.init_process()
2021-04-24T21:55:02.919818+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 129, in init_process
2021-04-24T21:55:02.919818+00:00 app[web.1]: self.load_wsgi()
2021-04-24T21:55:02.919819+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2021-04-24T21:55:02.919819+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-04-24T21:55:02.919820+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-04-24T21:55:02.919820+00:00 app[web.1]: self.callable = self.load()
2021-04-24T21:55:02.919820+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2021-04-24T21:55:02.919821+00:00 app[web.1]: return self.load_wsgiapp()
2021-04-24T21:55:02.919821+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2021-04-24T21:55:02.919821+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-04-24T21:55:02.919822+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 350, in import_app
2021-04-24T21:55:02.919822+00:00 app[web.1]: __import__(module)
2021-04-24T21:55:02.919823+00:00 app[web.1]: File "/app/MPLoadManagement/wsgi.py", line 12, in <module>
2021-04-24T21:55:02.919823+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-04-24T21:55:02.919823+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-04-24T21:55:02.919969+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-04-24T21:55:02.953092+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Shutting down: Master
2021-04-24T21:55:02.953195+00:00 app[web.1]: [2021-04-24 21:55:02 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-04-24T21:55:03.019883+00:00 heroku[web.1]: Process exited with status 3
2021-04-24T21:55:03.124137+00:00 heroku[web.1]: State changed from starting to crashed
Requirements.txt
appdirs==1.4.4
asgiref==3.3.1
astroid==2.5.2
beautifulsoup4==4.9.3
certifi==2020.12.5
distlib==0.3.1
dj-database-url==0.5.0
Django==3.1.7
django-autoslug==1.9.8
django-bootstrap-modal-forms==2.1.0
django-bootstrap4==2.3.1
django-crispy-forms==1.11.2
django-heroku==0.0.0
django-widget-tweaks==1.4.8
filelock==3.0.12
gunicorn==19.9.0
isort==5.8.0
lazy-object-proxy==1.6.0
mccabe==0.6.1
pipenv==2020.11.15
psycopg2-binary==2.8.6
pylint==2.7.4
pytz==2021.1
six==1.15.0
soupsieve==2.2.1
sqlparse==0.4.1
toml==0.10.2
virtualenv==20.4.4
virtualenv-clone==0.5.4
whitenoise==5.2.0
wrapt==1.12.1
在您的需求文件中,将 psycopg2-binary
更改为 psycopg2
您正在安装 django-heroku==0.0.0
这是您真正想要的吗?
我已经向 Heroku 部署了 5 个以上的项目,我从来没有遇到过这样的错误,但是从错误消息中可以明显看出 Django 可能没有安装,重新部署你的项目,看看它是否有效
我现在能够解决问题了。这是因为我没有创建生产部署所需的 static_root 和 staticfiles_storage 文件夹