gpt4 book ai didi

django - 由于导入错误,无法运行 gunicorn

转载 作者:行者123 更新时间:2023-12-04 19:42:11 28 4
gpt4 key购买 nike

我有一个 django==2.1virualenv 合作的项目.然后为了解决一些包问题,我创建了另一个 virtualenv为我的项目并激活它。但是,每当我运行 gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application我收到以下问题。

Traceback (most recent call last):
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/root/uzagro_4/agrosenv/lib/python3.5/site-
packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ImportError: No module named 'myproject'
[2019-01-17 04:16:14 +0500] [21107] [INFO] Worker exiting (pid: 21107)
[2019-01-17 04:16:14 +0500] [21104] [INFO] Shutting down: Master
[2019-01-17 04:16:14 +0500] [21104] [INFO] Reason: Worker failed to boot.

我不知道如何解决这个问题。这是我的 gunicorn.service 文件:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=nginx
WorkingDirectory=/home/root/uzagro_4
ExecStart=/home/root/uzagro_4/agrosenv/bin/gunicorn --workers 3 --bind
unix:/home/root/uzagro_4/myproject.sock uzagro_4.wsgi:application
[Install]
WantedBy=multi-user.target

和 nginx.conf 文件:
    server {
listen 80;
server_name agros.uz www.agros.uz;

location = /favicon.ico { access_log off; log_not_found off; }

location /static/ {
root /home/root/uzagro_4/;
}

location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/root/uzagro_4/myproject.sock;
}
}

先感谢您!

最佳答案

模块导入错误...我认为这是因为您在运行 gunicon 之前实际上并未启动 venv,因为您是直接从服务文件中执行此操作的。您可以在启动 gunicorn 之前编写一个带有一些命令的 bash 文件来启用 venv,这样它将在其中运行。看看这篇文章:

http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/

问候。

关于django - 由于导入错误,无法运行 gunicorn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54226856/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com