如何在 Ubuntu 的虚拟环境中为 uwsgi 安装 gevent 插件?

How to install gevent plugin for uwsgi in a virtual environment in Ubuntu?

我在 运行ning uWSGI (2.0.16) ubuntu 16.04

当我从 root 运行ning uWSGI 时它工作正常。但是,当我在虚拟环境中进入 运行 uWSGI 时,出现以下错误:-

uwsgi: unrecognized option '--gevent'
getopt_long() error

然后我在我的虚拟环境中检查uWSGI的插件列表,发现缺少gevent插件。

根据 uWSGI >= 1.4

的 uWSGI 文档

The gevent plugin is compiled in by default when the default profile is used. Doing the following will install the python plugin as well as the gevent one:

pip install uwsgi

但是通过pip install uwsgi安装uwsgi,还是无法在虚拟环境中获取gevent插件。但是,以类似的方式,当我在虚拟环境之外安装 uwsgi 时,gevent 插件已经可用。

我已经尝试安装 uwsgi-plugin-gevent-python

我必须使用 SSL 支持来构建 uwsgi,所以我使用 CFLAGS 来构建 uWSGI。 ssl 支持在我的虚拟环境中也不起作用。

你在virtualenv中安装了gevent吗?您是否指定了要产生的异步核心数?

我有运行下面的代码:

pip install uwsgi gevent
uwsgi --gevent 10

当然你应该添加配置来指定应用程序到运行以及uswgi应用程序应该在哪里监听连接。

希望对您有所帮助。

由于这个问题在 "uwsgi build plugin gevent support" 的许多变体中排名很高,我认为它可以使用一个答案。

您可以通过 运行ning 验证 uwsgi 没有加载 gevent 插件:

$ uwsgi --plugins-list

如果 gevent 未在 *** uWSGI loaded generic plugins *** 部分中列出,那么您可以编译它,这里是 python 3.4 的编译方法(我正在使用 Ubuntu 14.04 这里):

$ PYTHON=/usr/bin/python3.4 uwsgi --build-plugin "$UWSGI_DIR/plugins/gevent gevent34"

其中 UWSGI_DIR 是您的 uwsgi 安装目录路径。

如果您收到如下错误:

fatal error: Python.h: No such file or directory
 #include <Python.h>

您可能缺少 python3-dev 工具,在 Ubuntu 中,您可以使用以下方法安装这些工具:

$ apt-get install python3-dev

然后重新运行构建插件命令。

如果您没有收到错误,您的 UWSGI_DIR 中现在应该有一个名为 gevent34_plugin.so 的插件。您现在可以在启动时加载它:

$ uwsgi --plugins-dir $UWSGI_DIR --plugin gevent34 --plugins-list

gevent 应该列在 *** uWSGI loaded generic plugins *** 部分的某处。