【问题标题】:Deploying django app with gunicorn, Importerror in gunicorn log使用gunicorn部署django应用程序,gunicorn日志中的Importerror
【发布时间】:2016-11-03 13:43:06
【问题描述】:

我正在尝试根据本教程使用 gunicorn 和 nginx 部署 django 应用:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

但我无法让我的 gunicorn 正常工作,

这是我的 /etc/init/gunicorn.conf:

description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid me
setgid www-data


exec myprojectenv/bin/gunicorn --workers 3 --bind  unix:/myproject/myproject.sock myproject.wsgi:application

当我在我的 virtualenv 中运行时:

gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

一切正常。 但每次我启动 gunicorn 时,我的 gunicorn 错误日志中都会出现此错误:

ImportError: No module named 'myproject'

我检查了所有可能的选项,但没有任何改变。 我有什么遗漏吗? 提前致谢。

编辑:

我在 exec 之前添加了一个 chdir 行:

chdir /myproject/myprojectenv

我还在继续

ImportError: No module named 'myproject'

【问题讨论】:

  • 你的项目名称是什么:'myaproject''myproject'
  • 这是我的项目,有错字,我会改正的。

标签: python django ubuntu wsgi gunicorn


【解决方案1】:

当你手动运行它时,你大概已经在正确的目录中,所以 gunicorn 可以找到 myproject.wsgi 模块。但是在 upstart 下运行时,它不会在那个目录下,所以不知道在哪里找到文件。

您可以通过将chdir /path/to/my/virtualenv 放在exec 行之前来解决此问题。

【讨论】:

  • 我照你说的做了,但我又得到了这个:ImportError: No module named 'myproject',有什么想法吗?
  • 我再次将其更改为:chdir /path/to/myproject 并且它开始正常工作!谢谢!
  • 正如 Daniel 所说,使用 Upstart 脚本,您需要 chdir 进入项目所在的文件夹(这样 gunicorn 可以找到 myproject,并在 exec 部分中指定 virtualenv 的绝对路径脚本。
猜你喜欢
  • 2014-03-31
  • 2018-02-04
  • 2019-09-19
  • 1970-01-01
  • 2012-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-19
相关资源
最近更新 更多