我正在尝试为django项目安装带有systemd的gunicorn,但是它无法加载我的项目的另一个库。
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单元文件
[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,谢谢!
发布于 2016-04-04 21:13:04
解决了这个问题,systemd单元文件中的Environment var不应该有引号。
[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.targethttps://stackoverflow.com/questions/36411742
复制相似问题