uWSGI和Python> 3.4

Muh*_*bad 5 django uwsgi python-3.6

我有一个django项目,当前正在使用以下配置运行:

  • Debian 8
  • Python 3.4
  • 皇帝模式下的uWSGI

我从源代码安装了Python 3.6.1,并使用python 3.6创建了一个新的虚拟环境(我使用virtualenvwrapper),但是让该项目以uwsgi启动似乎有些麻烦。

配置文件如下:

[uwsgi]
plugins = python3
project = %n
module = myapp.wsgi:application
home = path_to_new_env
socket = /var/run/uwsgi-%n.sock
chdir = path_to_new_env/myapp/myapp
processes = 4
max-requests = 5000
chmod-socket = 666
chown-socket = user:user
master = True
vacuum = True
logto = /var/log/%n_LOG.log
buffer-size = 32768
Run Code Online (Sandbox Code Playgroud)

我的印象是该python3插件将包括对python 3.6的支持,但日志表明仍在使用Python 3.4.x解释器。

在已安装的uwsgi插件列表中,我看到了对python 2、3和3.4的支持,但仅此而已。我不确定启动时设置正确的解释器需要做什么。

任何意见,将不胜感激。

更新:我已经尝试为python 3.6构建一个uwsgi插件:

root@app:~# PYTHON=python3.6 uwsgi --build-plugin "/root/uwsgi-2.0.15/plugins/python python36"
*** uWSGI building and linking plugin from /root/uwsgi-2.0.15/plugins/python ***
[gcc -pthread] python36_plugin.so
/root/uwsgi-2.0.15/plugins/python/python_plugin.c: In function ‘uwsgi_python_atexit’:
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:380:11: error: ‘struct uwsgi_server’ has no member named ‘skip_atexit_teardown’
  if (uwsgi.skip_atexit_teardown)
           ^
/root/uwsgi-2.0.15/plugins/python/python_plugin.c: At top level:
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: unknown field ‘worker’ specified in initializer
  .worker = uwsgi_python_worker,
  ^
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: initialization from incompatible pointer type [-Werror]
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: (near initialization for ‘python36_plugin.exception_class’) [-Werror]
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: initialized field overwritten [-Werror=override-init]
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: (near initialization for ‘python36_plugin.exception_class’) [-Werror=override-init]
cc1: all warnings being treated as errors
/root/uwsgi-2.0.15/plugins/python/uwsgi_pymodule.c: In function ‘py_uwsgi_spooler_get_task’:
/root/uwsgi-2.0.15/plugins/python/uwsgi_pymodule.c:2107:2: error: implicit declaration of function ‘uwsgi_spooler_read_header’ [-Werror=implicit-function-declaration]
  if (uwsgi_spooler_read_header(task_path, spool_fd, &uh) ||
  ^
/root/uwsgi-2.0.15/plugins/python/uwsgi_pymodule.c:2108:3: error: implicit declaration of function ‘uwsgi_spooler_read_content’ [-Werror=implicit-function-declaration]
   uwsgi_spooler_read_content(spool_fd, spool_buf, &body, &body_len, &uh, &task_stat)) {
   ^
cc1: all warnings being treated as errors
*** unable to build python36 plugin ***
Run Code Online (Sandbox Code Playgroud)

Evh*_*vhz 5

我最近想出了一个解决方案,python3.6应用与服务器。

wget https://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar -xvzf uwsgi-latest.tar.gz

mv uwsgi-2.0.17 uwsgi
cd uwsgi
make PROFILE=nolang # no language defaults allows flexibility for python versions

PYTHON=python3.6 # or --> PYTHON=/usr/bin/python3.6

./uwsgi --build-plugin "plugins/python python36"
mv python36_plugin.so plugins/python
cd ..
sudo mv uwsgi /usr/local
sudo ln -s /usr/local/uwsgi/uwsgi /usr/local/bin/uwsgi
Run Code Online (Sandbox Code Playgroud)

然后,您可以在配置文件中使用它,如下所示:

[uwsgi]

plugins-dir = /usr/local/uwsgi/plugins/python
plugin = python36
Run Code Online (Sandbox Code Playgroud)

为您希望在 uwsgi 服务器上提供的任何其他 Python 版本模仿此过程。
更多帮助在这里


Muh*_*bad 0

解决方案:

1)下载uwsgi源tarball

2) 按照此处的构建说明进行操作

请注意,对于 python3.6,您需要使用该标志配置 python--enable-shared并在构建 uWsgi 插件之前声明一个额外的环境变量:export CFLAGS="$CFLAGS -fPIC"

3) 使用支持的插件安装新的 uwsgi 二进制文件:cp uwsgi /usr/local/bin/