macでpip install scipy

Keywords

  • Python

Contents

  • 1. 環境
  • 2. 問題
  • 3. lapackインストール
  • 4. リトライ

環境

macOS Catalina
バージョン 10.15.3

問題

/usr/local/bin/python3.9 -m pip install scipy

上記のように、scipyをインストールしようとしたところ、下記のエラーが発生してしまいました。

$  /usr/local/bin/python3.9 -m pip install scipy
Collecting scipy
  Downloading scipy-1.5.3.tar.gz (25.2 MB)
     |████████████████████████████████| 25.2 MB 764 kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: scipy
  Building wheel for scipy (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/[email protected]/bin/python3.9 /usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/yq/c_1sg4xx42sfdtdpx2pgvgbm0000gn/T/tmpb_peuhyp
       cwd: /private/var/folders/yq/c_1sg4xx42sfdtdpx2pgvgbm0000gn/T/pip-install-axv7imri/scipy
  Complete output (810 lines):
  Running from SciPy source directory.
  lapack_opt_info:
  lapack_mkl_info:
  customize UnixCCompiler
    libraries mkl_rt not found in ['/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib', '/usr/local/lib', '/usr/lib']
    NOT AVAILABLE
  
  openblas_lapack_info:
  customize UnixCCompiler
  customize UnixCCompiler
    libraries openblas not found in ['/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib', '/usr/local/lib', '/usr/lib']
    NOT AVAILABLE
  
  openblas_clapack_info:
  customize UnixCCompiler
  customize UnixCCompiler
    libraries openblas,lapack not found in ['/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib', '/usr/local/lib', '/usr/lib']
    NOT AVAILABLE
  
  flame_info:
  customize UnixCCompiler
    libraries flame not found in ['/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib', '/usr/local/lib', '/usr/lib']
    NOT AVAILABLE


中略


  ----------------------------------------
  ERROR: Failed building wheel for scipy
Failed to build scipy
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly

エラーメッセージを読むとmkl_rtというライブラリがないとのこと。

lapackインストール

python環境におけるscipyのインストールについてをみてみると、lapackが必要らしい。

LAPACKの実装が何かしら見つかればそれを使うので、MKL自体はなくても動きます。openblasとか。

brewでlapackをインストール

$ brew install lapack

リトライ

再度実行

$ /usr/local/bin/python3.9 -m pip install scipy
Collecting scipy
  Using cached scipy-1.5.3.tar.gz (25.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: scipy
  Building wheel for scipy (PEP 517) ... done
  Created wheel for scipy: filename=scipy-1.5.3-cp39-cp39-macosx_10_15_x86_64.whl size=18053295 sha256=5359eda7d8ad4c3ee334e545abe5aa4566114627dec91c0b12f3c0c10338ebfd
  Stored in directory: /Users/naokimachida/Library/Caches/pip/wheels/3c/4c/19/12f801a35938df49d8a3ed946877ddbdce412a1ccf0b4df48f
Successfully built scipy
Installing collected packages: scipy
Successfully installed scipy-1.5.3

scipyのインストールに成功しました。 よくわからない部分もありますが、開発環境ということもあり、とりあえずうごくのでokとします。