首页 > 解决方案 > 没有名为“gunicorn”的模块

问题描述

我正在尝试使用 gunicorn 和 nginx 为 Flask 服务这是我的 systemd 单元配置文件

[Unit]
Description=Gunicorn instance to serve odooErp
After=network.target

[Service]
User=tito
Group=www-data
WorkingDirectory=/home/tito/peg/odoo_api/peg_api
Environment="PATH=/home/tito/peg/odoo_api/peg_api/env/bin"
ExecStart=/home/tito/peg/odoo_api/peg_api/env/bin/gunicorn --workers 3 --bind unix:odooErp.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target

当我启动服务时,尽管使用 pip 安装了 gunicorn,但我遇到了以下错误

[0;1;31m●[0m odooErp.service - Gunicorn instance to serve productionOdoo
   Loaded: loaded (/etc/systemd/system/odooErp.service; enabled; vendor preset: enabled)
   Active: [0;1;31mfailed[0m (Result: exit-code) since Tue 2020-08-18 05:33:23 UTC; 1min 0s ago
 Main PID: 18305 (code=exited, status=1/FAILURE)
      CPU: 43ms

Aug 18 05:33:23 peg-test-01 systemd[1]: Started Gunicorn instance to serve odooErp.
Aug 18 05:33:23 peg-test-01 gunicorn[18305]: Traceback (most recent call last):
Aug 18 05:33:23 peg-test-01 gunicorn[18305]:   File "/home/tito/peg/odoo_api/peg_api/env/bin/gunicorn", line 7, in <module>
Aug 18 05:33:23 peg-test-01 gunicorn[18305]:     from gunicorn.app.wsgiapp import run
Aug 18 05:33:23 peg-test-01 gunicorn[18305]: ImportError: No module named 'gunicorn'
Aug 18 05:33:23 peg-test-01 systemd[1]: [0;1;39modooErp.service: Main process exited, code=exited, status=1/FAILURE[0m
Aug 18 05:33:23 peg-test-01 systemd[1]: [0;1;39modooErp.service: Unit entered failed state.[0m
Aug 18 05:33:23 peg-test-01 systemd[1]: [0;1;39modooErp.service: Failed with result 'exit-code'.[0m

标签: pythonnginxflaskgunicorn

解决方案


这可能是因为模块不在正确的路径中

如果你在windows上,你可以在你的环境中设置如下路径:在左下角搜索这台电脑>属性>高级系统设置>右下角的环境变量>在用户变量中单击PATH然后新建并设置路径


推荐阅读