首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django + gunicorn +系统问题

Django + gunicorn +系统问题
EN

Stack Overflow用户
提问于 2016-04-04 19:56:00
回答 1查看 2.4K关注 0票数 1

我正在尝试为django项目安装带有systemd的gunicorn,但是它无法加载我的项目的另一个库。

代码语言:javascript
复制
File "/home/ubuntu/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
gunicorn[6043]: return _bootstrap._gcd_import(name[level:], package, level)
gunicorn[6043]: ImportError: No module named 'templates'

模板是位于单独目录中的项目的另一部分。如果我尝试在我的/home/ubuntu/templates/中不使用$PYTHONPATH运行站点,我会得到同样的错误,我已经在systemd单元文件中添加了pythonpath,但是它没有做任何事情。

我可以用这个命令成功地运行gunicorn:

/home/ubuntu/venv/bin/gunicorn --pid /tmp/pid-gunicorn site_gfa.wsgi:application -b 0.0.0.0:8083

但我在系统中失败了

Systemd单元文件

代码语言:javascript
复制
[Unit]
Description="Site"
After=network.target

[Service]
PIDFile=/tmp/pid-gunicorn
User=ubuntu
Group=users
Environment=PYTHONPATH='/home/ubuntu/templates/'
WorkingDirectory=/home/ubuntu/gfa-apps/
ExecStart=/home/ubuntu/venv/bin/gunicorn --pid /tmp/pid-gunicorn site_gfa.wsgi:application -b 0.0.0.0:8083
PrivateTmp=true
Type=forking

[Install]
WantedBy=multi-user.target

我正在使用Python3.4和gunicorn 19.4.5运行CentOS7,谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-04 21:13:04

解决了这个问题,systemd单元文件中的Environment var不应该有引号。

代码语言:javascript
复制
[Unit]
Description="Site"
After=network.target

[Service]
PIDFile=/tmp/pid-gunicorn
User=ubuntu
Group=users
Environment=PYTHONPATH=/home/ubuntu/templates/
WorkingDirectory=/home/ubuntu/gfa-apps/
ExecStart=/home/ubuntu/venv/bin/gunicorn --pid /tmp/pid-gunicorn site_gfa.wsgi:application -b 0.0.0.0:8083
PrivateTmp=true
Type=forking

[Install]
WantedBy=multi-user.target
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36411742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档