使用 flask 和 gunicorn - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zcsnbb
V2EX    Python

使用 flask 和 gunicorn

  •  
  •   zcsnbb 2019-03-21 11:44:23 +08:00 5324 次点击
    这是一个创建于 2398 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在使用 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 下已经安装了各个依赖

    13 条回复    2019-03-22 11:36:07 +08:00
    xpresslink
        1
    xpresslink  
       2019-03-21 11:50:05 +08:00
    貌似是你安装的时候用了 pip install gunicorn, 实际上应该用 pip3 install xxxxxx
    建议还是用 venv 吧,激活环境后再 pip 安装第三方包。
    yemoluo
        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())

    你就会知道答案啦
    cissoid
        3
    cissoid  
       2019-03-21 11:56:19 +08:00
    which gunicorn
    zcsnbb
        4
    zcsnbb  
    OP
       2019-03-21 13:40:20 +08:00
    @xpresslink 是的 我是 pip install gunicorn 但是我看我的 pip freeze 下有 gunicorn 就是 python3.6 下有这个的
    zcsnbb
        5
    zcsnbb  
    OP
       2019-03-21 13:40:48 +08:00
    @GTim 我可能知道是为什么了,多谢
    zcsnbb
        6
    zcsnbb  
    OP
       2019-03-21 13:41:00 +08:00
    @cissoid 多谢
    zcsnbb
        7
    zcsnbb  
    OP
       2019-03-21 13:41:50 +08:00
    @GTim 想请教一下,这个 apt install 的 gunicorn 和 pip install 的 gunicorn 有点弄混了,这两个分别是什么呢
    yemoluo
        8
    yemoluo  
       2019-03-21 15:05:12 +08:00
    @zcsnbb apt install 用的是 python setup.py install ,对应的是 python,所以就看你的 python 是 3 还是 2 了

    pip install 就看 pip 本身对应的是 3 还是 2
    tisswb
        9
    tisswb  
       2019-03-21 16:42:29 +08:00
    没装 gevent 吧
    cz5424
        10
    cz5424  
       2019-03-21 19:04:30 +08:00
    pip install gevent

    指定 worker 需要安装
    cz5424
        11
    cz5424  
       2019-03-21 19:05:43 +08:00
    请读英文错误提示,已经很清晰的告诉你没有装依赖了
    Trim21
        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 模块。
    frostming
        13
    frostming  
       2019-03-22 11:36:07 +08:00
    你的 Python 包都装到哪了?
    https://frostming.com/2019/03-13/where-do-your-packages-go
    终结一切找不到包、可执行文件的问题
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3128 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 30ms UTC 12:29 PVG 20:29 LAX 05:29 JFK 08:29
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86