前提
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
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/18 02:20
2022/09/18 09:39 編集
2022/09/21 00:40