1. 程式人生 > >centos配置帶GPU的caffe 安裝依賴的包yum install找不到包

centos配置帶GPU的caffe 安裝依賴的包yum install找不到包

yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel

實際上,hdf5-devel這個安裝會找不到。

但是:yum install gflags-devel glog-devel lmdb-devel這個不成功,找不到。只能手動安裝:
# glog
    wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
    tar zxvf glog-0.3.3.tar.gz
    cd glog-0.3.3
    ./configure
    make && make install
連不上 google-glog.googlecode.com
從這裡下載:
http://download.csdn.net/download/chenguangxing3/6661667
安裝glog。
./configure --preifx=mypath
make
make install


    # gflags
    wget https://github.com/schuhschuh/gflags/archive/master.zip
    unzip master.zip
    cd gflags-master
    mkdir build && cd build
    export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
    make && make install

cmake的時候,提示版本不夠,需要2.8.12或以上,我的是2.8.11
升級cmake:https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz
 ./bootstrap
gmake
gmake install

再次安裝gflags成功。


    # lmdb
    git clone https://github.com/LMDB/lmdb
    cd lmdb/libraries/liblmdb
    make && make install
安裝成功。


安裝atlas:
yum install atlas


安裝python 開發包:
 yum install python-devel

安裝cython: http://cython.org/  下載0.24版的
http://cython.org/release/Cython-0.24.zip
進入解壓路徑,python setup.py install
耗時3分鐘左右。


安裝numpy
http://nbtelecom.dl.sourceforge.net/project/numpy/NumPy/1.8.0/numpy-1.8.0.zip
耗時3分鐘左右。



------------------------編譯安裝caffe--------------------------
參考:http://caffe.berkeleyvision.org/installation.html中的Compilation with Make部分。


cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)
make all
make test
make runtest

修改:
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
               /usr/lib/python2.7/dist-packages/numpy/core/include

為:(因為我的arrayobject.h在另外lib64的路徑下)
PYTHON_INCLUDE := /usr/include/python2.7 \
                /usr/lib64/python2.7/site-packages/numpy/core/include


修改:開啟CPU_ONLY := 1,並註釋掉:USE_CUDNN := 1。因為我的電腦沒有gpu相關的東西。

其他的沒改動。

報錯:
CXX src/caffe/blob.cpp
In file included from ./include/caffe/blob.hpp:8:0,
                 from src/caffe/blob.cpp:4:
./include/caffe/common.hpp:6:26: fatal error: glog/logging.h: No such file or directory
 #include <glog/logging.h>
因為沒有裝glog,所以再找辦法裝上先。

安裝後繼續編譯,報錯:
CXX src/caffe/blob.cpp
In file included from ./include/caffe/util/math_functions.hpp:11:0,
                 from src/caffe/blob.cpp:7:
./include/caffe/util/mkl_alternate.hpp:11:19: fatal error: cblas.h: No such file or directory
 #include <cblas.h>
沒有裝cblas,參考:http://blog.csdn.net/cleverysm/article/details/1925549,http://www.linuxidc.com/Linux/2015-02/113169.htm
http://www.netlib.org/blas/blast-forum/cblas.tgz
具體:
1. 編譯blas,進入BLAS目錄執行下面的命令

    gfortran -c  -O3    *.f                # 編譯所有的 .f 檔案,生成 .o檔案 
    ar rv libblas.a      *.o                # 連結所有的 .o檔案,生成 .a 檔案 

2. 編譯cblas,進入CBLAS目錄,首先根據自己的作業系統平臺,將某個Makefiel.XXX複製為Makefile.in,XXX表示作業系統。如果是Linux,那麼就將Makefile.LINUX 複製為 Makefile.in。

    cp ../BLAS/libblas.a  testing  # 將上一步編譯成功的 libblas.a 複製到 CBLAS目錄下的testing子目錄 
    make                                            # 編譯所有的目錄 

此時會在CBLAS安裝目錄下的lib目錄中產生一個靜態連結庫檔案cblas_LINUX.a,這個庫檔案和上面得到的libblas.a檔案就是我們所需要的。另外還需要的就是CBLAS/include中的cblas.h標頭檔案。將三個檔案全部拷貝到,你需呼叫的應用程式原始碼目錄中。

拷貝到路徑下:
cp include/cblas.h /usr/include/
cp lib/cblas_LINUX.a /usr/local/libcblas.a
cp testing/libblas.a /usr/local/lib


再次編譯,報錯:
src/caffe/layers/hdf5_data_layer.cpp:13:18: fatal error: hdf5.h: No such file or directory
 #include "hdf5.h"
記得上面已經安裝了hdf5-devel,怎麼會出這個錯?檢視一下,發現yum這個沒找到hdf5-devel,所以也就沒有安裝。
在docs/installion.md中,建議:but we suggest first installing the [Anaconda](https://store.continuum.io/cshop/anaconda/) Python distribution, which provides most of the necessary packages, as well as the `hdf5` library dependency.

準備安裝hdf5:
http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.16.tar
解壓後:
./configure --prefix=/usr/local/hdf5-1.8.3   ##指定安裝路徑,否則會預設安裝到當前路徑下。
make ##4分鐘左右
make install

此時,在Makefile.config中增加HDF5_DIRS的路徑到搜尋路徑下:
HDF5_DIRS :=/usr/local/hdf5-1.8.3/
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include $(HDF5_DIRS)/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib $(HDF5_DIRS)/lib



再次編譯,報錯:
In file included from src/caffe/util/db.cpp:2:0:
./include/caffe/util/db_leveldb.hpp:7:24: fatal error: leveldb/db.h: No such file or directory
 #include "leveldb/db.h"
                        ^
compilation terminated.
缺少了google的kv資料庫:leveldb,這個在installation.md中的Optional dependencies也提到了。
從這裡下載:https://github.com/google/leveldb
參考:https://techoverflow.net/blog/2012/12/14/compiling-installing-leveldb-on-linux/

解壓後,make
因為沒有不支援install,所以,要手工將這些include和生成的lib拷貝到需要的地方。
cp --preserve=links out-shared/libleveldb.so* /usr/local/lib  #只拷貝了動態庫。
cp -r include/leveldb/ /usr/local/include/


再次編譯,報錯:
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lcblas
/usr/bin/ld: cannot find -latlas
collect2: error: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

靜態庫的連結已經完成了,這個動態庫缺少了東西。上面安裝cblas的時候,發現確實是只產生了靜態庫,需要增加動態庫。
進入到CBLAS目錄下,將靜態庫轉為動態庫:
gcc -shared lib/cblas_LINUX.a testing/libblas.a -o libcblas.so
cp libcblas.so /usr/local/


再次編譯,報錯:
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lcblas
/usr/bin/ld: cannot find -latlas
collect2: error: ld returned 1 exit status

mv /usr/local/libcblas.* /usr/local/lib/  #就是把它們轉移到 /usr/local/lib下,否則還會報錯


再次編譯,報錯:
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -latlas
collect2: error: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

之前有安裝 yum install atlas
檢視:
[

[email protected] caffe-master]# ll /usr/lib64/atlas/
total 21304
lrwxrwxrwx. 1 root root       17 Apr  8 15:54 libsatlas.so.3 -> libsatlas.so.3.10
-rwxr-xr-x. 1 root root 10852104 Nov 20 13:43 libsatlas.so.3.10
lrwxrwxrwx. 1 root root       17 Apr  8 15:54 libtatlas.so.3 -> libtatlas.so.3.10
-rwxr-xr-x. 1 root root 10959464 Nov 20 13:43 libtatlas.so.3.10


再安裝yum install atlas-devel,檢視:
[
[email protected]
caffe-master]# ll /usr/lib64/atlas/
total 21304
lrwxrwxrwx. 1 root root       17 Apr  9 14:03 libsatlas.so -> libsatlas.so.3.10
lrwxrwxrwx. 1 root root       17 Apr  8 15:54 libsatlas.so.3 -> libsatlas.so.3.10
-rwxr-xr-x. 1 root root 10852104 Nov 20 13:43 libsatlas.so.3.10
lrwxrwxrwx. 1 root root       17 Apr  9 14:03 libtatlas.so -> libtatlas.so.3.10
lrwxrwxrwx. 1 root root       17 Apr  8 15:54 libtatlas.so.3 -> libtatlas.so.3.10
-rwxr-xr-x. 1 root root 10959464 Nov 20 13:43 libtatlas.so.3.10

參考:http://blog.sina.com.cn/s/blog_4c4668bb01013gsv.html
發現裡面有說到:
在 3.10.0 的 ATLAS 中沒有了 --with-netlib-lapack指定lapack_LINUX.a 只需要 --with-netlib-lapack-tarfile,給出下載的包就行,不需要自己在去編譯 LAPACK了。但是最後生成的 庫檔案也給整合了,不是上面的6個,而是兩個 
libsatals.so libtatlas.so, 去 BUILD/lib 裡面檢視 Makefile, 可以看到確實被整合了的。為了依其上的軟體能更通用,又不想自己去改Makefile的內容,就用老版本的組合了。

於是,我建立一個軟連結:
ln -s /usr/lib64/atlas/libsatlas.so /usr/lib64/libatlas.so
(如果我建立在atlas下,即ln -s /usr/lib64/atlas/libsatlas.so /usr/lib64/atlas/libatlas.so  還是找不到,就把它提到外面來了)


再次編譯,這次ok了。
[
[email protected]
caffe-master]# make all
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
CXX tools/caffe.cpp
CXX/LD -o .build_release/tools/caffe.bin
CXX tools/compute_image_mean.cpp
CXX/LD -o .build_release/tools/compute_image_mean.bin
CXX tools/convert_imageset.cpp
CXX/LD -o .build_release/tools/convert_imageset.bin
CXX tools/device_query.cpp
CXX/LD -o .build_release/tools/device_query.bin
CXX tools/extract_features.cpp
CXX/LD -o .build_release/tools/extract_features.bin
CXX tools/finetune_net.cpp
CXX/LD -o .build_release/tools/finetune_net.bin
CXX tools/net_speed_benchmark.cpp
CXX/LD -o .build_release/tools/net_speed_benchmark.bin
CXX tools/test_net.cpp
CXX/LD -o .build_release/tools/test_net.bin
CXX tools/train_net.cpp
CXX/LD -o .build_release/tools/train_net.bin
CXX tools/upgrade_net_proto_binary.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
CXX tools/upgrade_net_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
CXX tools/upgrade_solver_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin
CXX examples/cifar10/convert_cifar_data.cpp
CXX/LD -o .build_release/examples/cifar10/convert_cifar_data.bin
CXX examples/cpp_classification/classification.cpp
CXX/LD -o .build_release/examples/cpp_classification/classification.bin
CXX examples/mnist/convert_mnist_data.cpp
CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin
[[email protected] caffe-master]# 


接著是make test,沒有問題,花費5分鐘左右。
接著:make runtest,報錯:
[[email protected] caffe-master]# make runtest
.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or directory
make: *** [runtest] Error 127

但是在/usr/local/lib下有阿?
[[email protected] glog-0.3.3]# ll /usr/local/lib
total 5532
drwxr-xr-x. 3 root root     19 Apr  8 16:32 cmake
-rwxr-xr-x. 1 root root 130336 Mar 25 10:59 default.sfx
-rw-r--r--. 1 root root 792216 Apr  8 17:17 libblas.a
-rw-r--r--. 1 root root 387232 Apr  8 17:16 libcblas.a
-rwxr-xr-x. 1 root root   7691 Apr  9 11:39 libcblas.so
-rw-r--r--. 1 root root 628106 Apr  8 16:31 libgflags.a
-rw-r--r--. 1 root root 627712 Apr  8 16:31 libgflags_nothreads.a
-rw-r--r--. 1 root root 352318 Apr  8 16:59 libglog.a
-rwxr-xr-x. 1 root root    958 Apr  8 16:59 libglog.la
lrwxrwxrwx. 1 root root     16 Apr  8 16:59 libglog.so -> libglog.so.0.0.0
lrwxrwxrwx. 1 root root     16 Apr  8 16:59 libglog.so.0 -> libglog.so.0.0.0
-rwxr-xr-x. 1 root root 524192 Apr  8 16:59 libglog.so.0.0.0
-rwxr-xr-x. 3 root root 413462 Apr  9 11:26 libleveldb.so
-rwxr-xr-x. 3 root root 413462 Apr  9 11:26 libleveldb.so.1
-rwxr-xr-x. 3 root root 413462 Apr  9 11:26 libleveldb.so.1.18
-rw-r--r--. 1 root root 644748 Apr  8 16:33 liblmdb.a
-rwxr-xr-x. 1 root root 304783 Apr  8 16:33 liblmdb.so
drwxr-xr-x. 2 root root     23 Apr  8 16:59 pkgconfig

臨時解決方法:
export LD_LIBRARY_PATH=/usr/local/lib/
繼續make runtest,報錯:
[[email protected] caffe-master]# make runtest
.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libhdf5_hl.so.10: cannot open shared object file: No such file or directory
make: *** [runtest] Error 127

再來:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/hdf5-1.8.3/lib
這次ok了:
[ RUN      ] NeuronLayerTest/0.TestExpLayer
[       OK ] NeuronLayerTest/0.TestExpLayer (0 ms)
[ RUN      ] NeuronLayerTest/0.TestExpGradientBase2Shift1
[       OK ] NeuronLayerTest/0.TestExpGradientBase2Shift1 (1 ms)
[ RUN      ] NeuronLayerTest/0.TestLogLayerBase2
[       OK ] NeuronLayerTest/0.TestLogLayerBase2 (0 ms)
[ RUN      ] NeuronLayerTest/0.TestLogGradientBase2Shift1Scale3
[       OK ] NeuronLayerTest/0.TestLogGradientBase2Shift1Scale3 (2 ms)
[----------] 48 tests from NeuronLayerTest/0 (175 ms total)

[----------] Global test environment tear-down
[==========] 1050 tests from 146 test cases ran. (34229 ms total)
[  PASSED  ] 1050 tests.
但這個不是好的解決方法,我得永久修改這個連結路徑才行。
方法:
檢視 /etc/ld.so.conf
發現引用/etc/ld.so.conf.d/下的所有conf結尾的檔案,進入裡面
可以看到那個atlas的內容就一句話,指明瞭lib的路徑:/usr/lib64/atlas
新建一個conf檔案:/etc/ld.so.conf.d/glog.conf,裡面寫:/usr/local/lib
再新建一個conf檔案:/etc/ld.so.conf.d/hdf5.conf,裡面寫:/usr/local/hdf5-1.8.3/lib
最後執行:
/sbin/ldconfig -v

這樣,就不用再去搞那個LD_LIBRARY_PATH了。


重新執行一次完整流程:
make clean
make all  #3分鐘
make test #4分鐘
make runtest #1分鐘
make pycaffe #40秒

編譯python的包:
[[email protected] caffe-master]# make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
touch python/caffe/proto/__init__.py
PROTOC (python) src/caffe/proto/caffe.proto
[[email protected] caffe-master]# 

編譯好了python包後,要把這個模組加入到python的路徑下:(參考安裝說明:http://caffe.berkeleyvision.org/installation.html python部分)
export PYTHONPATH=/home/zzz/OpenSource/caffe-master/python:$PYTHONPATH
編輯/etc/profile,增加:
export PYTHONPATH=$PYTHONPATH:/home/zzz/OpenSource/caffe-master/python/


然後開啟python,匯入caffe:
[[email protected] caffe-master]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
/home/zzz/OpenSource/caffe-master/python/caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr<caffe::Net<float> > already registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
/home/zzz/OpenSource/caffe-master/python/caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr<caffe::Blob<float> > already registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
/home/zzz/OpenSource/caffe-master/python/caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr<caffe::Solver<float> > already registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zzz/OpenSource/caffe-master/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "/home/zzz/OpenSource/caffe-master/python/caffe/pycaffe.py", line 15, in <module>
    import caffe.io
  File "/home/zzz/OpenSource/caffe-master/python/caffe/io.py", line 2, in <module>
    import skimage.io
ImportError: No module named skimage.io
>>> 


報錯缺少 skimage.io
下載:https://pypi.python.org/packages/source/s/scikit-image/scikit-image-0.12.3.tar.gz#md5=04ea833383e0b6ad5f65da21292c25e1
解壓,進入,
python setup.py install
不成功,提示:
te-packages
Adding scikit-image 0.12.3 to easy-install.pth file
Installing skivi script to /usr/bin

Installed /usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg
Processing dependencies for scikit-image==0.12.3
Searching for dask[array]>=0.5.0
Reading https://pypi.python.org/simple/dask/
Best match: dask 0.8.1.macosx-10.5-x86-64
Downloading https://pypi.python.org/packages/any/d/dask/dask-0.8.1.macosx-10.5-x86_64.tar.gz#md5=6271cc3687493136a6b743dc5271ab80
Processing dask-0.8.1.macosx-10.5-x86_64.tar.gz
error: Couldn't find a setup script in /tmp/easy_install-h26472/dask-0.8.1.macosx-10.5-x86_64.tar.gz
[[email protected] scikit-image-0.12.3]# python

在python裡,import skimage.io會報:
>>> import skimage.io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/io/__init__.py", line 7, in <module>
    from .manage_plugins import *
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/io/manage_plugins.py", line 28, in <module>
    from .collection import imread_collection_wrapper
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/io/collection.py", line 12, in <module>
    from PIL import Image
ImportError: No module named PIL



原來用easy_install 這麼方便!這個easy_install 我的系統有。
easy_install Image
會自動搜尋依賴。
  File "/usr/lib64/python2.7/distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "setup.py", line 512, in build_extensions
ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting

沒有安裝成功。



下載:
http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
解壓後,進入目錄,執行:
python setup.py install
成功:
running install_scripts
copying build/scripts-2.7/pilconvert.py -> /usr/bin
copying build/scripts-2.7/pildriver.py -> /usr/bin
copying build/scripts-2.7/pilfile.py -> /usr/bin
copying build/scripts-2.7/pilfont.py -> /usr/bin
copying build/scripts-2.7/pilprint.py -> /usr/bin
changing mode of /usr/bin/pilconvert.py to 755
changing mode of /usr/bin/pildriver.py to 755
changing mode of /usr/bin/pilfile.py to 755
changing mode of /usr/bin/pilfont.py to 755
changing mode of /usr/bin/pilprint.py to 755
running install_egg_info
Writing /usr/lib64/python2.7/site-packages/PIL/PIL-1.1.7-py2.7.egg-info
creating /usr/lib64/python2.7/site-packages/PIL.pth
[[email protected] Imaging-1.1.7]# 

再次
>>> import skimage.io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/io/__init__.py", line 11, in <module>
    from ._io import *
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/io/_io.py", line 7, in <module>
    from ..color import rgb2grey
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/color/__init__.py", line 1, in <module>
    from .colorconv import (convert_colorspace,
  File "/usr/lib64/python2.7/site-packages/scikit_image-0.12.3-py2.7-linux-x86_64.egg/skimage/color/colorconv.py", line 58, in <module>
    from scipy import linalg
ImportError: No module named scipy

安裝:
[[email protected] Downloads]# easy_install scipy
Searching for scipy
Reading https://pypi.python.org/simple/scipy/
Best match: scipy 0.17.0
Downloading https://pypi.python.org/packages/source/s/scipy/scipy-0.17.0.zip#md5=28a4fe29e980804db162524f10873211
Processing scipy-0.17.0.zip
Writing /tmp/easy_install-YgsnC3/scipy-0.17.0/setup.cfg
Running scipy-0.17.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-YgsnC3/scipy-0.17.0/egg-dist-tmp-wyWVj4
/usr/lib64/python2.7/site-packages/numpy/distutils/system_info.py:1428: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
/usr/lib64/python2.7/site-packages/numpy/distutils/system_info.py:1439: UserWarning: 
    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.
  warnings.warn(LapackNotFoundError.__doc__)
/usr/lib64/python2.7/site-packages/numpy/distutils/system_info.py:1442: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [lapack_src]) or by setting
    the LAPACK_SRC environment variable.
  warnings.warn(LapackSrcNotFoundError.__doc__)
Running from scipy source directory.
error: no lapack/blas resources found
[[email protected] Downloads]# 
失敗!
從網上下載原始碼:http://ufpr.dl.sourceforge.net/project/scipy/scipy/0.16.1/scipy-0.16.1.tar.gz
python setup.py install
同樣報錯:
File "/usr/lib64/python2.7/site-packages/numpy/distutils/misc_util.py", line 935, in get_subpackage
    caller_level = caller_level + 1)
  File "/usr/lib64/python2.7/site-packages/numpy/distutils/misc_util.py", line 872, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "scipy/linalg/setup.py", line 20, in configuration
    raise NotFoundError('no lapack/blas resources found')
numpy.distutils.system_info.NotFoundError: no lapack/blas resources found
[[email protected] scipy-0.16.1]# 
看來要先解決這兩個問題。


反覆折騰都沒有搞定。。。。
參考:http://blog.sina.com.cn/s/blog_62dfdc740101aoo6.html
重新編譯atlas。 16:33~16:39



在等待過程,重新看numpy:
cp site.conf.example site.conf
將site.conf編輯為:
[DEFAULT]
library_dirs = /usr/local/lib
include_dirs = /usr/local/include
src_dirs = /home/gumh/Downloads/BLAS-3.6.0:/home/gumh/Downloads/lapack-3.1.1

[blas_opt]
libraries =f77blas,cblas,atlas

[lapack_opt]
libraries=lapack,f77blas,cblas,atlas


 [atlas]
 library_dirs = /usr/lib64/atlas/
 include_dirs = /usr/include/atlas

[amd]
amd_libs = amd
#
[umfpack]
umfpack_libs = umfpack

[fftw]
libraries = fftw3



然後執行:python setup.py build --fcompiler=gnu95
執行下去了,可以看到中間有在對上面設定的src路徑下的程式碼進行編譯。
然後python setup.py install

按照這個site.conf來去build scipy-0.16.1,失敗。
重新下載scipy-0.11.0 。https://pypi.python.org/packages/source/s/scipy/scipy-0.11.0.tar.gz#md5=842c81d35fd63579c41a8ca21a2419b9
解壓,啥都沒改u,閱讀了那個INSTALL.txt:
python setup.py install
直接就運行了,中間看到有在編譯那個lapack-3.1.1的檔案,我在這裡並沒有指定,應該是上面numpy中指定的被儲存起來了。
後面還是掛了:
/usr/bin/gfortran -Wall -Wall -shared build/temp.linux-x86_64-2.7/scipy/integrate/_odepackmodule.o -L/usr/local/lib -L/usr/lib64 -Lbuild/temp.linux-x86_64-2.7 -lodepack -llinpack_lite -lmach -lblas -lpython2.7 -lgfortran -o build/lib.linux-x86_64-2.7/scipy/integrate/_odepack.so
/usr/bin/ld: /usr/local/lib/libblas.a(dcopy.o): relocation R_X86_64_PC32 against undefined symbol `[email protected]@GLIBC_2.14' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
/usr/bin/ld: /usr/local/lib/libblas.a(dcopy.o): relocation R_X86_64_PC32 against undefined symbol `[email protected]@GLIBC_2.14' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
error: Command "/usr/bin/gfortran -Wall -Wall -shared build/temp.linux-x86_64-2.7/scipy/integrate/_odepackmodule.o -L/usr/local/lib -L/usr/lib64 -Lbuild/temp.linux-x86_64-2.7 -lodepack -llinpack_lite -lmach -lblas -lpython2.7 -lgfortran -o build/lib.linux-x86_64-2.7/scipy/integrate/_odepack.so" failed with exit status 1
[[email protected] scipy-0.11.0]# 

意思是/usr/local/lib/libblas.a這個是靜態庫,不能用於pic的動態連結。
那我就要編譯一個動態庫出來。
於是重新進入

    gfortran -c  -O3  -fPIC  *.f                #加上了-fPIC
    gcc -shared *.o -fPIC -o  libblas.so
 cp libblas.so /usr/local/lib/

再次執行 python setup.py install:
這次完成了:
/fftpack/tests/
copying scipy/fftpack/tests/fftw_single_ref.npz -> /usr/lib64/python2.7/site-packages/scipy/fftpack/tests/
copying scipy/fftpack/tests/gen_fftw_ref.py -> /usr/lib64/python2.7/site-packages/scipy/fftpack/tests/
creating /usr/lib64/python2.7/site-packages/scipy/weave/doc
copying scipy/weave/doc/tutorial.txt -> /usr/lib64/python2.7/site-packages/scipy/weave/doc/
copying scipy/weave/doc/tutorial_original.html -> /usr/lib64/python2.7/site-packages/scipy/weave/doc/
running install_egg_info
Writing /usr/lib64/python2.7/site-packages/scipy-0.11.0-py2.7.egg-info
running install_clib
[[email protected] scipy-0.11.0]# 
[[email protected] Downloads]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> 

ok,安裝完成!


回到我們的上一層問題:import skimage.io出錯,現在再來:
>>> import skimage.io
>>> 

ok!

繼續回到上一層問題:import caffe:
>>> import caffe
4.egg/skimage/_shared/_geometry.py", line 4, in <module>
    from matplotlib import _path, path, transforms
ImportError: No module named matplotlib

還有問題,缺少matplotlib:
用easy_install matplotlib的方式安裝。
太慢。
直接下載:https://pypi.python.org/packages/source/m/matplotlib/matplotlib-1.5.1.tar.gz#md5=f51847d8692cb63df64cd0bd0304fd20
解壓,進入,執行:
python setup.py build
提示缺少必須的依賴:
                        * The following required packages can not be built:
                        * freetype, png

解決:
yum install freetype-devel

下載libpng原始碼:http://tenet.dl.sourceforge.net/project/libpng/libpng14/older-releases/1.4.14/libpng-1.4.14.tar.gz
解壓,進入,執行:
./configure 
make
make check
make install
可以看到,安裝資訊:
make[2]: Leaving directory `/home/zzz/Downloads/libpng-1.4.14'
 /usr/bin/mkdir -p '/usr/local/share/man/man3'
 /usr/bin/install -c -m 644 libpng.3 libpngpf.3 '/usr/local/share/man/man3'
 /usr/bin/mkdir -p '/usr/local/share/man/man5'
 /usr/bin/install -c -m 644 png.5 '/usr/local/share/man/man5'
 /usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 libpng14.pc '/usr/local/lib/pkgconfig'
 /usr/bin/mkdir -p '/usr/local/include/libpng14'
 /usr/bin/install -c -m 644 png.h pngconf.h '/usr/local/include/libpng14'
make  install-data-hook
make[2]: Entering directory `/home/zzz/Downloads/libpng-1.4.14'
cd /usr/local/include; rm -f png.h pngconf.h
cd /usr/local/include; ln -s libpng14/png.h png.h
cd /usr/local/include; ln -s libpng14/pngconf.h \
    pngconf.h
cd /usr/local/lib/pkgconfig; rm -f libpng.pc
cd /usr/local/lib/pkgconfig; ln -s libpng14.pc libpng.pc
make[2]: Leaving directory `/home/zzz/Downloads/libpng-1.4.14'
make[1]: Leaving directory `/home/zzz/Downloads/libpng-1.4.14'
[[email protected] libpng-1.4.14]# 

再次執行matplotlib的編譯:
python setup.py build 成功。
python setup.py install 成功。


繼續import caffe,出錯:
ImportError: No module named google.protobuf.internal
參考:http://blog.csdn.net/littlestream9527/article/details/38734871

從網盤下載 :http://pan.baidu.com/s/1pJlZubT
解壓,進入,執行:
./configure
make
make install
ldconfig 

然後進入原始碼目錄的python子目錄:
cd python
執行:
python setup.py build 
python setup.py install

執行完後,再次的匯入caffe模組:
[[email protected] Downloads]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
/home/gumh/OpenSource/caffe-master/python/caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr<caffe::Net<float> > already registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
/home/gumh/OpenSource/caffe-master/python/caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr<caffe::Blob<float> > already registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
/home/gumh/OpenSource/caffe-master/python/caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr<caffe::Solver<float> > already registered; second conversion method ignored.
  from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
>>> 
成功了。