MacOSXにChainerを動かしたときの警告対策その2/OpenBLAS対応のNumPyに入れ替え

numpyをソースからインストールします。

目次

現状の numpy を削除する

$ pip3 uninstall numpy

Uninstalling numpy-1.15.4:
Would remove:
/usr/local/bin/f2py
/usr/local/lib/python3.7/site-packages/numpy-1.15.4.dist-info/*
/usr/local/lib/python3.7/site-packages/numpy/*
Proceed (y/n)? y
Successfully uninstalled numpy-1.15.4

ソースを獲得して準備する

$ git clone https://github.com/numpy/numpy
$ git checkout refs/tags/v1.15.4
$ cp site.cfg.example site.cfg

site.cfgをOpenBLAS使えるように編集する

[openblas]
libraries = openblas
library_dirs = /usr/local/opt/openblas/lib
include_dirs = /usr/local/opt/openblas/include
runtime_library_dirs = /usr/local/opt/openblas/lib

チェックします

$ python setup.py config

下記のメッセージが。。。

setup.py:378: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
run_build = parse_setuppy_commands()
Running from numpy source directory.
Cythonizing sources
Processing numpy/random/mtrand/randint_helpers.pxi.in
Processing numpy/random/mtrand/mtrand.pyx
Traceback (most recent call last):
File “/Users/hoge/Documents/chainer/numpy/tools/cythonize.py”, line 224, in <module>
main()
File “/Users/toshisan/Documents/chainer/numpy/tools/cythonize.py”, line 220, in main
find_process_files(root_dir)
File “/Users/hoge/Documents/chainer/numpy/tools/cythonize.py”, line 212, in find_process_files
process(cur_dir, fromfile, tofile, function, hash_db)
File “/Users/hoge/Documents/chainer/numpy/tools/cythonize.py”, line 171, in process
processor_function(fromfile, tofile)
File “/Users/hoge/Documents/chainer/numpy/tools/cythonize.py”, line 69, in process_pyx
raise OSError(‘Cython needs to be installed’)
OSError: Cython needs to be installed
Traceback (most recent call last):
File “setup.py”, line 403, in <module>
setup_package()
File “setup.py”, line 386, in setup_package
generate_cython()
File “setup.py”, line 214, in generate_cython
raise RuntimeError(“Running cythonize failed!”)
RuntimeError: Running cythonize failed!

う〜む。。。

Cythonをインストールする必要があります

Cythonって、C言語で書かれたライブラリをPythonから呼び出すためのインターフェース・・らしい(^^;

$ pip3 install cython

$ python3 setup.py config

/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: ‘define_macros’
warnings.warn(msg)

エラーじゃないからいいのかなぁ。。。やっちゃお!

$ python3 setup.py build
$ python3 setup.py install

さて、どうかな。。

$ python3 test.py
Hello

警告が消えてくれました!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です