我正在构建一个 django 项目(mailman3)并使用 uwsgi 访问它。从命令行在 virtualenv 中启动 uwsgi 时,它成功运行。
我正在尝试构建一个 systemd 服务来管理 uwsgi。它成功加载了 uwsgi 的虚拟环境并运行。但是当它尝试使用 attach-daemon 运行 django 进程时,manage.py 找不到 django 模块,即它没有拾取虚拟环境。
在 /etc/uwsgi.ini 文件中,我有:
virtualenv = /opt/mailman/venv
chdir = /opt/mailman/mailman-suite/mailman-suite_project
attach-daemon = ./manage.py qcluster
systemd 服务具有:
ExecStart=/opt/mailman/venv/bin/uwsgi --ini /etc/uwsgi.ini
当 systemd 启动服务时,我的错误日志报告:
[...]
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x558c5945bc30 pid: 15392 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 15392)
spawned uWSGI worker 1 (pid: 15416, cores: 2)
Traceback (most recent call last):
File "./manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'