我有一个django==2.1
的{{1}}项目。然后,为了解决一些程序包问题,我为项目创建了另一个virualenv
并将其激活。但是,每当我运行virtualenv
时,都会收到以下问题。
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
我不知道如何解决这个问题。这是我的gunicorn.service文件:
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.
还有nginx.conf文件:
[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
先谢谢您!
答案 0 :(得分:0)
模块导入错误...我想是因为您实际上没有在运行gunicon之前启动venv,因为您是直接从服务文件中执行此操作的。您可以在启动gunicorn之前用一些命令编写一个bash文件来启用venv,这样它将在其中运行。看一下这篇文章:
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
致谢。