Gunicorn:没有名为“/path/to/my/django/project”的模块

Gunicorn: No module named '/path/to/my/django/project'

我在 Ubuntu 16.04 系统上使用 gunicorn 和 nginx 来部署一个 django 项目,并想为 gunicorn 创建一个 systemd 服务。在/lib/systemd/system/gunicorn-mywebsite.service中,我写了以下代码:

ExecStart=/home/myusername/sites/pythonEnv/bin/gunicorn --bind unix:/tmp/mywebsite.socket /path/to/my/django/project.wsgi:application

但是当我运行service gunicorn-mywebsite start的时候,出现了问题No module named '/path/to/my/django/project'

如果我 运行 使用我 wsgi:application 的相对路径对我的 django 项目目录执行相同的命令,它将起作用。

我该如何解决这个问题?

你不能给 gunicorn 一个文件路径,它需要是一个模块路径,带有应用程序入口点名称。所以只是 project.wsgi:application。如果包含 project 的目录不在您的路径中,则使用 --pythonpath 到 gunicorn 告诉它它在哪里。