質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

1552閲覧

docker-compose上で「django-allauth」のパッケージをインストールできない

deango

総合スコア161

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2022/09/17 18:49

編集2022/09/17 18:58

前提

pipenvの環境をdockerを使用して複製を試みていますが、
docker-compose上で「django-allauth」のパッケージをインストールできず困っています。

発生している問題・エラーメッセージ

Dockerfileで以下のコマンドを実行した際のエラーです。(distutilsというコンパイラが見つからないようです。)
RUN pipenv install django-allauth

エラーメッセージ(文字数制限のため一部省略しています) > [7/9] RUN pipenv install django-allauth: #12 5.204 Creating a virtualenv for this project... ~省略~ #12 9.206✔ Successfully created virtual environment! #12 11.16 Virtualenv location: /root/.local/share/virtualenvs/app-lp47FrbD #12 11.41 Installing django-allauth... Error: An error occurred while installing django-allauth! Error text: Collecting django-allauth #12 42.14 Downloading django-allauth-0.51.0.tar.gz (709 kB) ~省略~ #12 42.14 Building wheels for collected packages: django-allauth, cffi #12 42.14 Building wheel for django-allauth (setup.py): started #12 42.14 Building wheel for django-allauth (setup.py): finished with status 'done' #12 42.14 Created wheel for django-allauth: filename=django_allauth-0.51.0-py3-none-any.whl size=1036034 sha256=783f241f0f2761d3320e6dbf91778a01aae461b0c4718df0a91500e020cbad87 #12 42.14 Stored in directory: /root/.cache/pipenv/wheels/6a/ab/b0/317637be62256bb375d7361c84371a141f847e72cc8b222a1f #12 42.14 Building wheel for cffi (setup.py): started #12 42.14 Building wheel for cffi (setup.py): finished with status 'error' #12 42.14 Running setup.py clean for cffi #12 42.14 Successfully built django-allauth #12 42.14 Failed to build cffi #12 42.14 Installing collected packages: types-cryptography, pytz, urllib3, typing-extensions, sqlparse, pyjwt, pycparser, oauthlib, idna, defusedxml, charset-normalizer, certifi, requests, python3-openid, cffi, asgiref, requests-oauthlib, Django, cryptography, django-allauth #12 42.14 Running setup.py install for cffi: started #12 42.14 Running setup.py install for cffi: finished with status 'error' #12 42.14 error: subprocess-exited-with-error #12 42.14 #12 42.14 × python setup.py bdist_wheel did not run successfully. #12 42.14 │ exit code: 1 #12 42.14 ╰─> [49 lines of output] #12 42.14 #12 42.14 No working compiler found, or bogus compiler options passed to #12 42.14 the compiler from Python's standard "distutils" module. See #12 42.14 the error messages above. Likely, the problem is not related #12 42.14 to CFFI but generic to the setup.py of any Python package that #12 42.14 tries to compile C code. (Hints: on OS/X 10.8, for errors about #12 42.14 -mno-fused-madd see http://stackoverflow.com/questions/22313407/ #12 42.14 Otherwise, see https://wiki.python.org/moin/CompLangPython or #12 42.14 the IRC channel #python on irc.libera.chat.) #12 42.14 #12 42.14 Trying to continue anyway. If you are trying to install CFFI from #12 42.14 a build done in a different context, you can ignore this warning. #12 42.14 #12 42.14 /root/.local/share/virtualenvs/app-lp47FrbD/lib/python3.7/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead. #12 42.14 warnings.warn(msg, warning_class) #12 42.14 running bdist_wheel #12 42.14 running build #12 42.14 running build_py #12 42.14 creating build #12 42.14 creating build/lib.linux-x86_64-cpython-37 #12 42.14 creating build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/verifier.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/lock.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/pkgconfig.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/error.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/api.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/model.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/cparser.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/vengine_gen.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/ffiplatform.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/recompiler.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/__init__.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/commontypes.py -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/_cffi_include.h -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/parse_c_type.h -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/_embedding.h -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-cpython-37/cffi #12 42.14 warning: build_py: byte-compiling is disabled, skipping. #12 42.14 #12 42.14 running build_ext #12 42.14 building '_cffi_backend' extension #12 42.14 creating build/temp.linux-x86_64-cpython-37 #12 42.14 creating build/temp.linux-x86_64-cpython-37/c #12 42.14 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DFFI_BUILDING=1 -I/root/.local/share/virtualenvs/app-lp47FrbD/include -I/usr/local/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-cpython-37/c/_cffi_backend.o #12 42.14 error: command 'gcc' failed: No such file or directory: 'gcc' #12 42.14 [end of output] ~省略~ ------ executor failed running [/bin/sh -c pipenv install django-allauth]: exit code: 1 ERROR: Service 'django-nyapu' failed to build : Build failed

該当のソースコード

Dockerの設定は以下です。

Dockerfile

1# 公式からpython3.7 on alpine linuxイメージをpull 2FROM python:3.7-alpine 3 4# 作業ディレクトリを設定 5WORKDIR /usr/src/app 6 7# 環境変数を設定 8# Pythonがpyc filesとdiscへ書き込むことを防ぐ 9ENV PYTHONDONTWRITEBYTECODE 1 10# Pythonが標準入出力をバッファリングすることを防ぐ 11ENV PYTHONUNBUFFERED 1 12 13# apkで依存関係のインストール 14RUN apk update \ 15 && apk add --virtual build-deps gcc python3-dev musl-dev \ 16 && apk add postgresql-dev \ 17 && apk del build-deps \ 18 && apk add libffi-dev 19 20# pipenvをインストール 21RUN pip install --upgrade pip \ 22 && pip install pipenv 23 24# ホストのpipfileをコンテナの作業ディレクトリにコピー 25COPY ./Pipfile /usr/src/app/Pipfile 26 27# pipfileからパッケージをインストールしてDjango環境を構築 28RUN pipenv install --skip-lock --system --dev 29 30# pipfileからのインストールではエラーが出るパッケージは個別にインストール 31RUN pipenv install django-allauth 32 33# entrypoint.shをコピー 34COPY ./entrypoint.sh /usr/src/app/entrypoint.sh 35 36# ホストのカレントディレクトリ(現在はappディレクトリ)を作業ディレクトリにコピー 37COPY . /usr/src/app/ 38 39# entrypoint.shを実行 40ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

pipfileの設定は以下です。
ローカルでこの環境を作成し、pipfileにまとめています。
django-allauthもこちらのpipfileに記述していたのですが、
エラーの切り分けのため、現状は個別にインストールするようにしています。

pipfile

1```entrypoint.sh 2[[source]] 3name = "pypi" 4url = "https://pypi.org/simple" 5verify_ssl = true 6 7[dev-packages] 8 9[packages] 10Django = "3.2.14" 11psycopg2-binary = "*" 12django-ses = "*" 13django-widget-tweaks = "*" 14selenium = "*" 15 16[requires] 17python_version = "3.7"

entrypoint.sh

1if [ "$DATABASE" = "postgres" ] 2then 3 echo "Waiting for postgres..." 4 5 while ! nc -z $DATABASE_HOST $DATABASE_PORT; do 6 sleep 0.1 7 done 8 9 echo "PostgreSQL started" 10fi 11 12python /usr/src/app/nyapu/manage.py flush --no-input 13python /usr/src/app/nyapu/manage.py migrate 14 15exec "$@"

試したこと

このエラーが出る前、「libffiが必要」とのエラーも出ていました。
「libffi-dev」のインストールをDockerfileに追加したところ、「libffiが必要」とのエラーは解消しました。

distutilsのエラーは解消されず、
distutilsについて調べたのですが、pythonに標準で入っているとの情報しかなく、
エラーが出る原因がわからないため質問しました。

また、django-allauthをインストールしない場合は、
正常にdocker環境構築完了します。

お力添えいただけますでしょうか。

補足情報(FW/ツールのバージョンなど)

OS:Ubuntu(WSL2)

・ローカル
python:3.8
postgeres:12.12

・docker-compose
python:3.7-alpinepython:3.7-alpine
postgres:10.17-alpine

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

結論

build-baseをインストールすれば動きました

shell

1# apk add build-base libffi-dev 2# pip install django-allauth 3> result: Success

辿り着くまでの経路

まず普通にコンテナを立てます

shell:host

1$ docker run -it --rm python:3.7-slim sh

shell:python3.7.slim.container

1# apk add build-base libffi-dev 2 3> 途中省きます 4 note: This error originates from a subprocess, and is likely not a problem with pip. 5error: legacy-install-failure 6 7× Encountered error while trying to install package. 8╰─> cffi 9 10note: This is an issue with the package mentioned above, not pip. 11hint: See above for output from the failure. 12WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available. 13You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

cffiが必要だよと出たのでencountered error while trying to install package. cffiで検索し
下記参考記事を見つけました
Docker python:alpineでcffiのコンパイルに失敗する - スタック・オーバーフロー

その後、下記でインストールは成功しました。

shell:python3.7.slim.container

1# apk add build-base libffi-dev 2# pip install django-allauth

一つ一つコンテナ立ててテストしていけば他のライブラリのインストールでも必要なものは見つけやすいと思うので、
躓いたら綺麗なコンテナで一つ一つ手順を追っていくのがいいかなと思います。
(マージするタイミングで躓いたら同じように複数のライブラリやパッケージをインストールして何でエラーが出るのかわかれば大体ググれば出ます)

投稿2022/09/18 02:12

sk-sora--ypi

総合スコア528

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

deango

2022/09/18 09:39 編集

詳しい情報ありがとうございます!大変参考になりました。 alpineについてはbuild-baseをインストールすることで、django-allauthのインストール成功しました! ですがパフォーマンスの観点であまり推奨されてないとのことなので、slimで設定してみようと思います!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問