LoginSignup
0
0

【Python x Docker】uwsgiパッケージのインストールでエラーが出た場合

Posted at

エラー概要

dockerビルド中に以下のエラーに遭遇。
使用したイメージはpython:3.6-slim-busterイメージです。

...(省略)
install --record /tmp/pip-record-89kpydwp/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/uWSGI Check the logs for full command output.
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

原因

uwsgiパッケージのインストール中にエラーが発生しているよう。
このパッケージはC言語で書かれた部分があり、そのコンパイルにはPythonの開発ヘッダーファイルやコンパイラなどの追加の依存関係が必要とのこと。

python:3.6-slim-busterイメージは、(サイズを小さく保つために)これらの依存関係が含まれていないようですね。普通にpython:3.6ならこのエラーは出ませんでした。

対処法

以下のようにインストールしてあげることでエラーがなくなりました。

FROM python:3.6-slim-buster

RUN apt-get update && apt-get install -y \
    build-essential \
    python3-dev \
    libpcre3 \
    libpcre3-dev \

これでuwsgiのインストール時に必要なコンパイル環境が整うようになりました。

ちなみにuWSGIとは、PythonでWebサービスを動かすためのアプリケーションサーバのこと(対応言語はPythonだけではない)。
こんなイメージですね。

HTTP client ↔ Nginx ↔ uWSGI ↔ Python app
引用元:https://en.wikipedia.org/wiki/UWSGI

WSGIプロトコルを実装している、PythonアプリケーションとWebサーバー間の標準的なインターフェースです。WSGIについては以前こんな記事も書いたのでご参考までに。

Pythonを含む複数のプログラミング言語をサポートするWebサーバーであり、アプリケーションサーバーです。uWSGIは、WebアプリケーションとWebサーバー間の通信を管理するために使用され、特にPythonのWebアプリケーションでよく使用されます。uWSGI自体は、WSGI(Web Server Gateway Interface)プロトコルを実装しており、PythonアプリケーションとWebサーバー間の標準的なインターフェースを提供します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0