我在使用 flask 和 gunicorn 在服务器部署一个服务的时候,出现了这个问题
ubu*********$ python -V Python 3.6.5 :: Anaconda, Inc. ubuntu@ip:~***********r$ gunicorn -c gunicorn.conf app:app Error: class uri 'gevent' invalid or not found: [Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 143, in load_class mod = import_module('.'.join(components)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/usr/lib/python2.7/dist-packages/gunicorn/workers/ggevent.py", line 22, in <module> raise RuntimeError("You need gevent installed to use this worker.") RuntimeError: You need gevent installed to use this worker. ]
我在本地运行是没有问题的,本地有创建虚拟环境,但是服务器上没有创建虚拟环境,我认为跟这个有关系,但是其他的都是在 python3 下运行的,为什么这个会去找 python2 呢,我在 python3 下已经安装了各个依赖
1 xpresslink 2019-03-21 11:50:05 +08:00 貌似是你安装的时候用了 pip install gunicorn, 实际上应该用 pip3 install xxxxxx 建议还是用 venv 吧,激活环境后再 pip 安装第三方包。 |
2 yemoluo 2019-03-21 11:55:15 +08:00 饿, 先用命令 > which gunicorn /usr/local/bin/gunicorn 查看这个命令存在哪里 然后使用 > cat /usr/local/bin/gunicorn 查看文件的内容,不出意外,看第一行 #!/usr/local/opt/python/bin/python3.7 # -*- coding: utf-8 -*- import re import sys from gunicorn.app.wsgiapp import run if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(run()) 你就会知道答案啦 |
![]() | 3 cissoid 2019-03-21 11:56:19 +08:00 which gunicorn |
4 zcsnbb OP @xpresslink 是的 我是 pip install gunicorn 但是我看我的 pip freeze 下有 gunicorn 就是 python3.6 下有这个的 |
7 zcsnbb OP @GTim 想请教一下,这个 apt install 的 gunicorn 和 pip install 的 gunicorn 有点弄混了,这两个分别是什么呢 |
8 yemoluo 2019-03-21 15:05:12 +08:00 |
![]() | 9 tisswb 2019-03-21 16:42:29 +08:00 没装 gevent 吧 |
![]() | 10 cz5424 2019-03-21 19:04:30 +08:00 pip install gevent 指定 worker 需要安装 |
![]() | 11 cz5424 2019-03-21 19:05:43 +08:00 请读英文错误提示,已经很清晰的告诉你没有装依赖了 |
![]() | 12 Trim21 2019-03-21 19:14:07 +08:00 via Android usr/lib/python2.7/dist-packages/gunicorn/workers/ggevent.py 其实这里已经告诉你用的是 Python2.7 了 为了避免用错误的 Python 版本运行,你可以考虑用 python3 -m pip install module_name 来安装 然后用 python3 -m module_name 来运行一些 py 模块。 |
![]() | 13 frostming 2019-03-22 11:36:07 +08:00 |