使用OpenBLAS集成編譯numpy

遇到這樣一個錯誤

/usr/local/lib/python2.7/site-packages/chainer/_environment_check.py:38: UserWarning: Accelerate has been detected as a NumPy backend library.
vecLib, which is a part of Accelerate, is known not to work correctly with Chainer.
We recommend using other BLAS libraries such as OpenBLAS.
For details of the issue, please see
https://docs.chainer.org/en/stable/tips.html#mnist-example-does-not-converge-in-cpu-mode-on-mac-os-x.

需要使用OpenBLAS集成編譯numpy
首先安裝openblas

$ brew install openblas
$ cd ~/github
$ git clone git://github.com/numpy/numpy.git numpy
$ cd numpy
$ cp site.cfg.example site.cfg

編輯site.cfg

[ALL]
library_dirs = /usr/local/opt/openblas/lib
include_dirs = /usr/local/opt/openblas/include
[atlas]
library_dirs = openblas
include_dirs = 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

編輯 ~/.bash_profile 添加

export LDFLAGS=-I/usr/local/opt/openblas/lib
export CPPFLAGS=-L/usr/local/opt/openblas/include
export PKG_CONFIG_PATH=/usr/local/opt/openblas/lib/pkgconfig

執(zhí)行

python setup.py build && python setup.py install

出現(xiàn)錯誤提示

fatal error: 'endian.h' file not found

首先需要安裝Command Line Tools (macOS 10.X) for XCode 10.X

xcode-select --install

MacOS 10.14之前版本,同時會自動生成"/usr/include"文件, 包括 "/usr/include/machine/endian.h".
MacOS 10.14起,文件不會自動升成,需要手動安裝 /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

如果出現(xiàn)權(quán)限不足錯誤

Adding numpy 1.16.0.dev0+11a316e to easy-install.pth file
error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/easy-install.pth'

可以改用

sudo python setup.py build && sudo python setup.py install
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容