How to use uWSGI with Python 3.7 in Ubuntu 18.x

Step-by-step how-to guide to use uWSGI with Python 3.7 for Ubuntu 18.04 and 18.10.

images/uwsgi-python.svg

Preface

In both Ubuntu 18.04 (Bionic Beaver) and 18.10 (Cosmic Cuttlefish) the uWSGI plugin for Python 3 use the default version 3.6.

It’s possible to compile an uWSGI plugin using the official Python 3.7 package, and we will see how to do it step by step.

Steps

Packages

Install all needed packages to build the plugin

$ sudo apt install \
python3.7 python3.7-dev uwsgi uwsgi-src uuid-dev libcap-dev libpcre3-dev

Build

Build the plugin with correct python version

$ cd ~
$ export PYTHON=python3.7
$ uwsgi --build-plugin "/usr/src/uwsgi/plugins/python python37"

Install

Change the plugin directory and set its permissions

$ sudo mv python37_plugin.so /usr/lib/uwsgi/plugins/python37_plugin.so
$ sudo chmod 644 /usr/lib/uwsgi/plugins/python37_plugin.so

Test

The uWSGI test command with Python 3.7 plugin give the same result for both Ubuntu 18.04 and 18.10.

$ uwsgi --plugin python37 -s :0
...
Python version: 3.7.1 (default, Oct 22 2018, 11:21:55)  [GCC 8.2.0]
...

 2019-03-13   1 min read      Howto   #GNU/Linux 🐧 #uWSGI 🇺 #Python 🐍 #Ubuntu 👥