0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[docker / scipy] ERROR: Unknown compiler(s): [['gfortran'], ['flang-new'], ['flang'], ['nvfortran'], ['pgfortran'], ['ifort'], ['ifx'], ['g95']] の対策

Posted at

1. 症状

docker build 中に、 scipy の build に失敗する。

2. Dependencies

以下のどの docker image でも、この記事の方法で対処できていた。

Item Version
docker image python:3.13.8-slim-trixie
or python:3.12.12-slim-trixie
or python:3.11.14-slim-trixie
or python:3.10.19-trixie
scipy 1.13.1

3. 解決策

記事のタイトルの通りのエラーであれば、以下の対処法で解決可能です。

Dockerfile
RUN apt -y update && apt -y upgrade
RUN apt -y install --no-install-recommends gfortran libopenblas-dev

細かいことはどうでもいいという人は、 Dockerfile に上記記述を書いてささっと解決してしまいましょう!

エラー文から原因を特定する方法を知りたい方は、「4.」以下も見てみてください。

4. 具体的な問題と対処法

以下のようなエラーログが出ている場合、この記事の対処法で対処できると思います。

エラーは何種類かありましたので、それぞれ確認してみてください。

3-1. エラー1

#0 86.18 Collecting scipy==1.13.1 (from -r requirements.txt (line 2))
#0 86.20   Downloading scipy-1.13.1.tar.gz (57.2 MB)
#0 87.02      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.2/57.2 MB 69.7 MB/s  0:00:00
#0 89.08   Installing build dependencies: started
#0 96.28   Installing build dependencies: finished with status 'done'
#0 96.29   Getting requirements to build wheel: started
#0 96.37   Getting requirements to build wheel: finished with status 'done'
#0 96.37   Installing backend dependencies: started
#0 97.55   Installing backend dependencies: finished with status 'done'
#0 97.55   Preparing metadata (pyproject.toml): started
#0 99.08   Preparing metadata (pyproject.toml): finished with status 'error'
#0 99.08   error: subprocess-exited-with-error
#0 99.08   
#0 99.08   × Preparing metadata (pyproject.toml) did not run successfully.
#0 99.08   │ exit code: 1
#0 99.08   ╰─> [53 lines of output]
#0 99.08       + meson setup /tmp/pip-install-t3cicjw2/scipy_9675f3f9e3d448c9b4bfb489c59e15be /tmp/pip-install-t3cicjw2/scipy_9675f3f9e3d448c9b4bfb489c59e15be/.mesonpy-zlcn5vht -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=/tmp/pip-install-t3cicjw2/scipy_9675f3f9e3d448c9b4bfb489c59e15be/.mesonpy-zlcn5vht/meson-python-native-file.ini
#0 99.08       The Meson build system
#0 99.08       Version: 1.9.1
#0 99.08       Source dir: /tmp/pip-install-t3cicjw2/scipy_9675f3f9e3d448c9b4bfb489c59e15be
#0 99.08       Build dir: /tmp/pip-install-t3cicjw2/scipy_9675f3f9e3d448c9b4bfb489c59e15be/.mesonpy-zlcn5vht
#0 99.08       Build type: native build
#0 99.08       Project name: scipy
#0 99.08       Project version: 1.13.1
#0 99.08       C compiler for the host machine: cc (gcc 14.2.0 "cc (Debian 14.2.0-19) 14.2.0")
#0 99.08       C linker for the host machine: cc ld.bfd 2.44
#0 99.08       C++ compiler for the host machine: c++ (gcc 14.2.0 "c++ (Debian 14.2.0-19) 14.2.0")
#0 99.08       C++ linker for the host machine: c++ ld.bfd 2.44
#0 99.08       Cython compiler for the host machine: cython (cython 3.0.12)
#0 99.08       Host machine cpu family: aarch64
#0 99.08       Host machine cpu: aarch64
#0 99.08       Program python found: YES (/usr/local/bin/python3.13)
#0 99.08       Found pkg-config: YES (/usr/bin/pkg-config) 1.8.1
#0 99.08       Run-time dependency python found: YES 3.13
#0 99.08       Program cython found: YES (/tmp/pip-build-env-nr672swj/overlay/bin/cython)
#0 99.08       Compiler for C supports arguments -Wno-unused-but-set-variable: YES
#0 99.08       Compiler for C supports arguments -Wno-unused-function: YES
#0 99.08       Compiler for C supports arguments -Wno-conversion: YES
#0 99.08       Compiler for C supports arguments -Wno-misleading-indentation: YES
#0 99.08       Library m found: YES
#0 99.08       
#0 99.08       ../meson.build:78:0: ERROR: Unknown compiler(s): [['gfortran'], ['flang-new'], ['flang'], ['nvfortran'], ['pgfortran'], ['ifort'], ['ifx'], ['g95']]
#0 99.08       The following exception(s) were encountered:
#0 99.08       Running `gfortran --help` gave "[Errno 2] No such file or directory: 'gfortran'"
#0 99.08       Running `gfortran --version` gave "[Errno 2] No such file or directory: 'gfortran'"
#0 99.08       Running `gfortran -V` gave "[Errno 2] No such file or directory: 'gfortran'"
#0 99.08       Running `flang-new --help` gave "[Errno 2] No such file or directory: 'flang-new'"
#0 99.08       Running `flang-new --version` gave "[Errno 2] No such file or directory: 'flang-new'"
#0 99.08       Running `flang-new -V` gave "[Errno 2] No such file or directory: 'flang-new'"
#0 99.08       Running `flang --help` gave "[Errno 2] No such file or directory: 'flang'"
#0 99.08       Running `flang --version` gave "[Errno 2] No such file or directory: 'flang'"
#0 99.08       Running `flang -V` gave "[Errno 2] No such file or directory: 'flang'"
#0 99.08       Running `nvfortran --help` gave "[Errno 2] No such file or directory: 'nvfortran'"
#0 99.08       Running `nvfortran --version` gave "[Errno 2] No such file or directory: 'nvfortran'"
#0 99.08       Running `nvfortran -V` gave "[Errno 2] No such file or directory: 'nvfortran'"
#0 99.08       Running `pgfortran --help` gave "[Errno 2] No such file or directory: 'pgfortran'"
#0 99.08       Running `pgfortran --version` gave "[Errno 2] No such file or directory: 'pgfortran'"
#0 99.08       Running `pgfortran -V` gave "[Errno 2] No such file or directory: 'pgfortran'"
#0 99.08       Running `ifort --help` gave "[Errno 2] No such file or directory: 'ifort'"
#0 99.08       Running `ifort --version` gave "[Errno 2] No such file or directory: 'ifort'"
#0 99.08       Running `ifort -V` gave "[Errno 2] No such file or directory: 'ifort'"
#0 99.08       Running `ifx --help` gave "[Errno 2] No such file or directory: 'ifx'"
#0 99.08       Running `ifx --version` gave "[Errno 2] No such file or directory: 'ifx'"
#0 99.08       Running `ifx -V` gave "[Errno 2] No such file or directory: 'ifx'"
#0 99.08       Running `g95 --help` gave "[Errno 2] No such file or directory: 'g95'"
#0 99.08       Running `g95 --version` gave "[Errno 2] No such file or directory: 'g95'"
#0 99.08       Running `g95 -V` gave "[Errno 2] No such file or directory: 'g95'"
#0 99.08       
#0 99.08       A full log can be found at /tmp/pip-install-t3cicjw2/scipy_9675f3f9e3d448c9b4bfb489c59e15be/.mesonpy-zlcn5vht/meson-logs/meson-log.txt
#0 99.08       [end of output]
#0 99.08   
#0 99.08   note: This error originates from a subprocess, and is likely not a problem with pip.
#0 99.09 error: metadata-generation-failed
#0 99.09 
#0 99.09 × Encountered error while generating package metadata.
#0 99.09 ╰─> See above for output.
#0 99.09 
#0 99.09 note: This is an issue with the package mentioned above, not pip.
#0 99.09 hint: See above for details.
------
failed to solve: executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

ダラダラとエラー文が吐かれますが、重要なのはここです。

../meson.build:78:0: ERROR: Unknown compiler(s): [['gfortran'], ['flang-new'], ['flang'], ['nvfortran'], ['pgfortran'], ['ifort'], ['ifx'], ['g95']]

上記の8つのパッケージが足りないようです。
まずは gfortran から用意してあげましょう。

以下の記述を Dockerfile に入れることで、 gfortran を Docker イメージに入れてあげることができます。pip install よりも先にこの gfortran がインストールされるようにしましょう。

Dockerfile
RUN apt -y update && apt -y upgrade
RUN apt -y install --no-install-recommends gfortran

これにより、 gfortran がないことによる問題は解決します。

Error 2

gfortran を入れた後の環境では、以下のようなエラーになりました。

#0 86.10 Collecting scipy==1.13.1 (from -r requirements.txt (line 2))
#0 86.13   Downloading scipy-1.13.1.tar.gz (57.2 MB)
#0 87.02      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.2/57.2 MB 64.5 MB/s  0:00:00
#0 89.18   Installing build dependencies: started
#0 95.95   Installing build dependencies: finished with status 'done'
#0 95.95   Getting requirements to build wheel: started
#0 96.04   Getting requirements to build wheel: finished with status 'done'
#0 96.04   Installing backend dependencies: started
#0 96.93   Installing backend dependencies: finished with status 'done'
#0 96.93   Preparing metadata (pyproject.toml): started
#0 99.91   Preparing metadata (pyproject.toml): finished with status 'error'
#0 99.91   error: subprocess-exited-with-error
#0 99.91   
#0 99.91   × Preparing metadata (pyproject.toml) did not run successfully.
#0 99.91   │ exit code: 1
#0 99.91   ╰─> [43 lines of output]
#0 99.91       + meson setup /tmp/pip-install-e_m5ewqq/scipy_6f6b226425e04f04a094014770ad5f10 /tmp/pip-install-e_m5ewqq/scipy_6f6b226425e04f04a094014770ad5f10/.mesonpy-ypeafcek -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=/tmp/pip-install-e_m5ewqq/scipy_6f6b226425e04f04a094014770ad5f10/.mesonpy-ypeafcek/meson-python-native-file.ini
#0 99.91       The Meson build system
#0 99.91       Version: 1.9.1
#0 99.91       Source dir: /tmp/pip-install-e_m5ewqq/scipy_6f6b226425e04f04a094014770ad5f10
#0 99.91       Build dir: /tmp/pip-install-e_m5ewqq/scipy_6f6b226425e04f04a094014770ad5f10/.mesonpy-ypeafcek
#0 99.91       Build type: native build
#0 99.91       Project name: scipy
#0 99.91       Project version: 1.13.1
#0 99.91       C compiler for the host machine: cc (gcc 14.2.0 "cc (Debian 14.2.0-19) 14.2.0")
#0 99.91       C linker for the host machine: cc ld.bfd 2.44
#0 99.91       C++ compiler for the host machine: c++ (gcc 14.2.0 "c++ (Debian 14.2.0-19) 14.2.0")
#0 99.91       C++ linker for the host machine: c++ ld.bfd 2.44
#0 99.91       Cython compiler for the host machine: cython (cython 3.0.12)
#0 99.91       Host machine cpu family: aarch64
#0 99.91       Host machine cpu: aarch64
#0 99.91       Program python found: YES (/usr/local/bin/python3.13)
#0 99.91       Found pkg-config: YES (/usr/bin/pkg-config) 1.8.1
#0 99.91       Run-time dependency python found: YES 3.13
#0 99.91       Program cython found: YES (/tmp/pip-build-env-ouvhtmfu/overlay/bin/cython)
#0 99.91       Compiler for C supports arguments -Wno-unused-but-set-variable: YES
#0 99.91       Compiler for C supports arguments -Wno-unused-function: YES
#0 99.91       Compiler for C supports arguments -Wno-conversion: YES
#0 99.91       Compiler for C supports arguments -Wno-misleading-indentation: YES
#0 99.91       Library m found: YES
#0 99.91       Fortran compiler for the host machine: gfortran (gcc 14.2.0 "GNU Fortran (Debian 14.2.0-19) 14.2.0")
#0 99.91       Fortran linker for the host machine: gfortran ld.bfd 2.44
#0 99.91       Compiler for Fortran supports arguments -Wno-conversion: YES
#0 99.91       Checking if "-Wl,--version-script" links: YES
#0 99.91       Program pythran found: YES 0.15.0 0.15.0 (/tmp/pip-build-env-ouvhtmfu/overlay/bin/pythran)
#0 99.91       Found CMake: /usr/bin/cmake (3.31.6)
#0 99.91       Run-time dependency xsimd found: NO (tried pkgconfig and cmake)
#0 99.91       Run-time dependency threads found: YES
#0 99.91       Library npymath found: YES
#0 99.91       Library npyrandom found: YES
#0 99.91       pybind11-config found: YES (/tmp/pip-build-env-ouvhtmfu/overlay/bin/pybind11-config) 2.12.1
#0 99.91       Run-time dependency pybind11 found: YES 2.12.1
#0 99.91       Run-time dependency scipy-openblas found: NO (tried pkgconfig)
#0 99.91       Run-time dependency openblas found: NO (tried pkgconfig and cmake)
#0 99.91       Run-time dependency openblas found: NO (tried pkgconfig and cmake)
#0 99.91       
#0 99.91       ../scipy/meson.build:163:9: ERROR: Dependency "OpenBLAS" not found, tried pkgconfig and cmake
#0 99.91       
#0 99.91       A full log can be found at /tmp/pip-install-e_m5ewqq/scipy_6f6b226425e04f04a094014770ad5f10/.mesonpy-ypeafcek/meson-logs/meson-log.txt
#0 99.91       [end of output]
#0 99.91   
#0 99.91   note: This error originates from a subprocess, and is likely not a problem with pip.
#0 99.92 error: metadata-generation-failed
#0 99.92 
#0 99.92 × Encountered error while generating package metadata.
#0 99.92 ╰─> See above for output.
#0 99.92 
#0 99.92 note: This is an issue with the package mentioned above, not pip.
#0 99.92 hint: See above for details.
------
failed to solve: executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

今度は重要なのはここです。

../scipy/meson.build:163:9: ERROR: Dependency "OpenBLAS" not found, tried pkgconfig and cmake

不足パッケージが OpenBLAS だけになりましたね。

openblas は以下のようにインストール可能でした。

Dockerfile
RUN apt -y update && apt -y upgrade
RUN apt -y install --no-install-recommends gfortran libopenblas-dev

このようにしてあげれば、scipy が無事インストールされます( *¯ ꒳¯*)✨

5. 参考

linux の Docker じゃなくて、 MacOS 上で作業している場合は、以下の記事の方法で解決できる模様。本当に解決できてるのかどうかはわからないけど、 thumb up のアイコンが押されている。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?