Theanoをcentosにインストールした。
DeeplearnigのライブラリにはTheanoと聞いて。
ちょっとローカルのスペックではもの足りないので、計算用のcentosにTheanoをインストールしたときのメモ。pythonとパッケージのバージョン問題で詰まった。というかエラーのタコ殴りにあった。
とりあえず、開発ツールをあんまりインストールしてないみたいだったので、
sudo yum groupinstall "Development tools"
あと、centosにpython2.4しか入ってなかったから、python2.7を入れて、virtualenvで環境を作った。
http://akiniwa.hatenablog.jp/entry/2013/11/23/233155
Theano動かすまでに、いろんなエラーでた。
- libpython2.7.aのエラー
- UnicodeDecodeError
- /usr/bin/ld: cannot find -lpython2.7
- numpy.distutils.system_info.BlasNotFoundError
- numpy.distutils.system_info.LapackNotFoundError:
- numpyとscipyのバージョン
libpython2.7.aのエラー
Exception: Compilation failed (return status=1): /usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC. /usr/local/lib/libpython2.7.a: could not read symbols: Bad value. collect2: ld はステータス 1 で終了しました.
というエラー。現在使用しているpythonの共有ライブラリの依存を調べたときに、libpython2.x.soがないとエラーになる。
調べてみると、
ldd /usr/local/bin/python linux-vdso.so.1 => (0x00007fffc2dff000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00000037e6600000) libdl.so.2 => /lib64/libdl.so.2 (0x00000037e6a00000) libutil.so.1 => /lib64/libutil.so.1 (0x00000037e7a00000) libm.so.6 => /lib64/libm.so.6 (0x00000037e5e00000) libc.so.6 => /lib64/libc.so.6 (0x00000037e6200000) /lib64/ld-linux-x86-64.so.2 (0x00000037e5a00000)
これはlibpythonの.soファイルがないので、theanoが動作しない。
以下のように、.soファイルが存在するpythonでvirtualenvを作れば、おっけー。
linux-vdso.so.1 => (0x00007fff751ff000) libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00000037e7e00000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00000037e6600000) libdl.so.2 => /lib64/libdl.so.2 (0x00000037e6a00000) libutil.so.1 => /lib64/libutil.so.1 (0x00000037e7a00000) libm.so.6 => /lib64/libm.so.6 (0x00000037e5e00000) libc.so.6 => /lib64/libc.so.6 (0x00000037e6200000) /lib64/ld-linux-x86-64.so.2 (0x00000037e5a00000)
UnicodeDecodeError
UnicodeDecodeError: 'ascii' codec can't decode byte.....
というエラー。こちらを参考に。
site-package内に、sitecustomize.pyというファイルを作ればいいらしい。
import sys sys.setdefaultencoding('utf-8')
/usr/bin/ld: cannot find -lpython2.7
これは、numpyのエラー。pythonのライブラリのパスがちゃんと指定できてない。
参考
libpython.so.1.0は/home/hoge/usr/local/lib/に置いてあるので、パスの指定を.bash_profileに書いて解決。
export LD_LIBRARY_PATH=/home/hoge/usr/local/lib:$LD_LIBRARY_PATH export LIBRARY_PATH=/home/hoge/usr/local/lib:$LIBRARY_PATH
numpy.distutils.system_info.BlasNotFoundError
BLASが見つからないとおっしゃっている。
numpy.distutils.system_info.BlasNotFoundError: Blas(http://www.netlib.org/blas/) libraries not found. Directories to search for the libraries can be specified in the numpy/distutils/site.cfg file (section [blas])or by setting
このエラーは、Python scipy needs BLAS? - Stack OverflowをBLASの部分を読んだ。
mkdir /home/hoge/py-env0/src/ cd /home/hoge/py-env0/src/ wget http://www.netlib.org/blas/blas.tgz tar xzf blas.tgz cd BLAS gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c *.f ar r libfblas.a *.o ranlib libfblas.a rm -rf *.o export BLAS=/home/hoge/py-env0/src/BLAS/libfblas.a
numpy.distutils.system_info.LapackNotFoundError:
LAPACKがないよー
numpy.distutils.system_info.LapackNotFoundError: Lapack (http://www.netlib.org/lapack/) libraries not found. Directories to search for the libraries can be specified in the numpy/distutils/site.cfg file (section [lapack]) or by setting the LAPACK environment variable.
wget http://www.netlib.org/lapack/lapack.tgz tar xzf lapack.tgz mv lapack-3.5.0/ LAPACK cd LAPACK/ cp INSTALL/make.inc.gfortran make.inc
make.incを編集する。OPTSとNOOPTを以下のように変更する。
OPTS = -O2 -m64 -fPIC NOOPT = -m64 -fPIC
$ make lapacklib $ export LAPACK=/home/hoge/py-env0/src/LAPACK/liblapack.a
numpyとscipyのバージョン
blas_info = numpy.distutils.__config__.blas_opt_info AttributeError: 'module' object has no attribute '__config__'
theanoをインポートしたら、__config__がないとか、versionがないとかいうエラーがでる。
site-packageにあるtheanoをみると、確かにversion.pyとかは見つかる。
theanoはpipでinstallして、そのときにnumpyとscipyは自動でとっていたバージョンが原因っぽい。
numpy (1.8.0) scipy (0.12.0)
両方ともアンインストールして、
pip install numpy==1.7.1 pip install scipy==0.10.0
これでおk。
ところで、make installとかのときに、ドン引きするくらいwarningがでるのはなんなんだろう。いつもスルーしてるけど。