nginx Gunicorn模块未找到错误:没有名为'django'的模块

ddhy6vgd  于 2023-01-01  发布在  Nginx
关注(0)|答案(3)|浏览(208)

我尝试按照this教程部署一个django应用程序,在启动gunicorn时,我使用了以下命令:gunicorn -b 127.0.0.1:8000 wsgi:application,位于我的www.example.com所在的文件夹中wsgi.py。

文件名为wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

application = get_wsgi_application()

我得到了以下错误:

[2019-07-19 20:54:39 -0300] [7786] [INFO] Starting gunicorn 19.9.0
[2019-07-19 20:54:39 -0300] [7786] [INFO] Listening at: http://127.0.0.1:8000 (7786)
[2019-07-19 20:54:39 -0300] [7786] [INFO] Using worker: sync
[2019-07-19 20:54:39 -0300] [7789] [INFO] Booting worker with pid: 7789
[2019-07-19 20:54:39 -0300] [7789] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.6/dist-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/home/ubuntu/renato-sfera/mysite/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
[2019-07-19 20:54:39 -0300] [7789] [INFO] Worker exiting (pid: 7789)
[2019-07-19 20:54:39 -0300] [7786] [INFO] Shutting down: Master
[2019-07-19 20:54:39 -0300] [7786] [INFO] Reason: Worker failed to boot.

可能是什么呢?我可以发布解决问题所需的内容

643ylb08

643ylb081#

刚刚遇到这个错误。我不得不在virtualenv中强制安装我的需求
当venv激活时:

pip install -I -r requirements.txt

最初我只是强制安装了django,但它缺少依赖项。

ovfsdjhp

ovfsdjhp2#

过去两天都有同样的问题
1.确保您正在从项目目录(而不是wsgi文件夹)运行该命令。
1.确保它是django的正确版本。
1.尝试在虚拟环境中运行。
1.安装uwsgi模块:
pip 3安装uwsgi
希望能有所帮助!

ipakzgxi

ipakzgxi3#

sudo apt安装python3-开发默认-libmysqlclient-开发构建-基本libssl-dev -y
我得到了这样一个团队的帮助,也许并不是那里需要的一切。

相关问题