【发布时间】:2021-11-24 20:24:08
【问题描述】:
我已遵循本指南 (https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04),但目前在尝试通过 gunicorn 服务文件 (/etc/systemd/system/gunicorn.service) 运行 gunicorn 时看到以下内容:
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: File "/opt/envs/automation-console-env/bin/gunicorn", line 5, in <module>
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: from gunicorn.app.wsgiapp import run
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: ModuleNotFoundError: No module named 'gunicorn'
gunicorn.service 文件包含以下内容:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/opt/envs/automation-console-env
ExecStart=/opt/envs/automation-console-env/bin/gunicorn --timeout 600 --log-level debug --error-log /var/log/automation-console-env_error.log --access-logfile /var/log/automation-console-env_access.log --workers 3 --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi:application
[Install]
WantedBy=multi-user.target
手动运行 gunicorn 可以正常工作:
gunicorn --bind 0.0.0.0:8000 myproject.wsgi
这在我不得不将我的 Python 版本从 3.5.2 升级到 3.9 之前就可以工作,由于一些问题,我最终不得不重新创建虚拟环境,所以我认为这不一定是服务的问题文件,而是我的 Python/Gunicorn 安装。
如果有人能提供一些建议,将不胜感激:)
【问题讨论】:
标签: python django nginx virtualenv gunicorn