SUSE Linux Enterprise 11 離線安裝 DLIB 人臉識別 python機器學習模塊

python機器學習模塊安裝
html

個人博客:http://www.cnblogs.com/wglIT/p/7525046.htmlnode

 

環境:SUSE Linux Enterprise 11 sp4  離線安裝python

說明:在安裝dlib時依賴的基礎 環境較多,先升級gcc,以適應c++ 11的使用;須要用到cmake編譯工具,boost這個c++庫,BLAS。python升級到2.7以上版本。linux

############################################################################ios

一,安裝相關依賴包 c++

安裝部分依賴:sql

sudo zypper install -y gcc-c++ gcc                           
sudo zypper install -y yum install gcc-gfortran
sudo zypper install boost                                                
sudo zypper install boost-devel
sudo zypper install libX11-devel
sudo zypper install openssl-devel

另外一種方式:下載rpm包,手動安裝相關依賴bootstrap

rpm -ihv boost-devel-1.36.0-12.6.49.x86_64.rpm
rpm -ihv bzip2-devel-1.0.5-7.el6_0.x86_64.rpm
rpm -ihv gdbm-devel-1.8.3-374.25.x86_64.rpm
rpm -ihv glibc-devel-2.11.3-17.54.1.x86_64.rpm
rpm -ihv keyutils-devel-1.2-107.29.15.x86_64.rpm
rpm -ihv krb5-devel-1.6.3-133.49.66.1.x86_64.rpm
rpm -ihv libboost_date_time1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_filesystem1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_graph1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_iostreams1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_math1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_mpi1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_program_options1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_python1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_regex1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_serialization1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_signals1_36_0-1.36.0-12.3.1.x86_64.rpm
rpm -ihv libboost_system1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_test1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_thread1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libboost_wave1_36_0-1.36.0-12.6.49.x86_64.rpm
rpm -ihv libcom_err-devel-1.41.9-2.14.3.x86_64.rpm
rpm -ihv libdbi-devel-0.8.3-4.el6.x86_64.rpm
rpm -ihv libopenssl-devel-0.9.8j-0.70.1.x86_64.rpm
rpm -ihv libselinux-devel-2.0.91-4.2.1.x86_64.rpm
rpm -ihv libsepol-devel-2.0.41-2.2.9.x86_64.rpm
rpm -ihv libX11-devel-1.6.3-9.3.x86_64.rpm
rpm -ihv ncurses-libs-5.7-4.20090207.el6.x86_64.rpm
rpm -ihv openssl-devel-1.0.1e-57.el6.x86_64.rpm
rpm -ihv python-devel-2.6.9-0.35.1.x86_64.rpm
rpm -ihv readline-devel-5.2-147.27.35.x86_64.rpm
rpm -ihv sqlite3-devel-3.7.6.3-1.4.4.1.x86_64.rpm
rpm -ihv xorg-x11-proto-devel-7.4-1.35.47.x86_64.rpm
rpm -ihv zlib-devel-1.2.7-0.12.3.x86_64.rpm

#############################################小程序

二,升級gcc 4.9.3  bash

參考: http://blog.csdn.net/xiexievv/article/details/50620170

(1)   下載

http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2

     tar xjvf gcc-4.9.3.tar.bz2
     cd gcc-4.9.3
     ./contrib/download_prerequisites
  • 安裝gcc須要5個組件,download_prerequisites 的任務就是下載這些組件分別是:

          cloog-0.18.1

          gmp-4.3.2

          isl-0.12.2

          mpc-0.8.1

          mpfr-2.4.2

  • 若是遇到download_prerequisites裏面的地址沒法訪問 
    推薦自行下載這些組件到目錄gcc-4.9.3/ 
    而後將download_prerequisites裏面的wget所有註釋掉,再執行 :

          ./contrib/download_prerequisites

  • 作好上面的準備就能夠configure了,建議另建一個目錄來存放編譯文件,默認安裝目錄是 /usr/local/ 能夠使用 –prefix 修改自定義路徑。

(2)編譯

    cd ..
    mkdir gcc-4.9.3-build-temp
    cd gcc-4.9.3-build-temp
    ../gcc-4.9.3/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
    make -j 4
    make install
  • · 編譯過程當中報莫名其妙的錯誤,嘗試使用root用戶或者root權限編譯
  • · 編譯過程很慢,一切順利的話,取決於你的配置40分鐘-1個小時後再來看結果吧
  • · 在/etc/profile中配置庫文件和頭文件路徑
       export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64/:$LD_LIBRARY_PATH
       export C_INCLUDE_PATH=/usr/local/include/:$C_INCLUDE_PATH
       export CPLUS_INCLUDE_PATH=/usr/local/include/:$CPLUS_INCLUDE_PATH
  • 執行 gcc -v 能夠看到下面的信息
  • gcc -v
使用內建 specs。

COLLECT_GCC=gcc

COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.9.3/lto-wrapper

目標:x86_64-unknown-linux-gnu

配置爲:../gcc-4.9.3/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

線程模型:posix

gcc 版本 4.9.3 (GCC)

(3)  升級gdb

升級完gcc還須要升級gdb!!! 由於版本不匹配等緣由致使調試的時候 print變量提示找不到符號,以及其餘莫名其妙的問題…

這裏我選擇安裝的時候gdb-7.9 ,安裝gdb須要4個組件 ,python,python-devel ,texinfo,ncurses-devel

編譯gdb時報錯誤 configure: error: no termcap library found 是缺乏 ncurses-devel

編譯過程當中遇到莫名奇妙的報錯,例如:ser-unix.c:118:1: error: conflicting types for ‘get_tty_state’,清理乾淨configure目錄,使用root用戶安裝就行了

sudo zypper install texinfo
sudo zypper install ncurses-devel
sudo zypper install python-devel

wget http://mirrors.ustc.edu.cn/gnu/gdb/gdb-7.9.tar.gz

tar xzvf gdb-7.9.tar.gz
cd gdb-7.9
./configure --with-python
sudo make
sudo make install
  • · 若是在安裝過程當中提示找不到makeinfo命令或其餘錯誤,切換root用戶再試一次
  • · 沒有python的支持也能夠編譯去掉–with-python選項就好了,可是gdb是沒法加載python腳本的,例如c++ 的 pretty-printer 腳本是沒法使用的

############################################

三,升級python到2.7

1,下載 

https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz

2,上傳,解壓

sudo  tar -zxvf Python-2.7.8.tgz

3,安裝:cd Python-2.7.8 ; 

(1)sudo mkdir /usr/local/python27;
(2)sudo yum install zlib-devel  openssl-devel
(3)sudo ./configure --prefix=/usr/local/python27  --enable-shared CFLAGS=-fPIC

 (./configure --prefix=/usr/local/python27 --enable-optimizations --enable-shared CFLAGS=-fPIC )

 (sudo env PYTHON_CONFIGURE_OPTS="--enable-shared" ./configure --prefix=/usr/local/python27)

(4)sudo make    

若出如下錯誤,參考下面解決辦法

http://blog.csdn.net/huanle0610/article/details/41174943

(5)sudo  make install 
(6)sudo mv /usr/bin/python /usr/bin/python_old
(7)sudo ln -s /usr/local/python27/bin/python2.7    /usr/bin/python

(8)將/usr/bin/下的cc,c++,gcc等軟鏈接到python2.7

     ln -s /usr/local/bin/cc     /usr/bin/cc            
     ln -s /usr/local/bin/c++    /usr/bin/c++
     ln -s /usr/local/bin/gcc    /usr/bin/gcc

(9)python      #終端下測試

若報錯: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No su

參考:http://blog.csdn.net/wanyanxgf/article/details/8021641

#############################################

四,boost安裝 

參考:http://www.cnblogs.com/findumars/p/6253092.html

1、下載並解壓boost 1.58 源代碼

      能夠去boost的官網下載http://jaist.dl.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.tar.bz2

      解壓 tar -xjf boost_1_58_0.tar.bz2

2、運行bootstrap.sh

     bootstrap.sh是用來檢查安裝環境的,若是報錯了,看一下是缺乏了什麼,安裝一下便可(g++)。

./bootstrap.sh --prefix=/usr/local/boost   --without-icu --with-python=/usr/local/python27

(./bootstrap.sh --with-libraries=python)

     運行完成以後會在當前目錄生成一些文件,用於下一步安裝。

3、安裝boost庫到指定目錄

      若是想安裝boost庫到指定目錄,好比說usr/local目錄,能夠使用下面的命令來進行。

mkdir ../ boostbuild

Sudo ./b2 install --without-mpi   --build-type=complete --layout=tagged    --build-dir=../boostbuild

(sudo ./b2 --prefix=/usr/local/boost install)

       安裝之後編譯代碼的時候仍是要指定目錄,能夠將它添加到環境變量/etc/profile下:CPLUS_INCLUDE_PATH和LIBRARY_PATH等環境變量。

 
 

export CPLUS_INCLUDE_PATH=/usr/local/boost/include/:/usr/local/boost/include/boost/:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/boost/lib
export PYTHON_INCLUDE_PATH=/usr/local/boost/include/:/usr/local/boost/include/boost:$PYTHON_INCLUDE_PATH
export BOOST_LIBRARYDIR=/usr/local/boost/lib/:$BOOST_LIBRARYDIR
export BOOST_ROOT=/usr/local/boost
export BOOST_HOME=/usr/local/boost
export BOOST_INCLUDE_DIR=/usr/local/boost/include:/usr/local/boost/:/usr/local/boost/include/boost
export BOOST_LIBRARYDIR=/usr/local/boost/lib:/usr/local/boost

 

4、測試一下

先寫一個簡單的獲取當前日期的小程序

代碼

#include <boost/date_time/gregorian/gregorian.hpp>

#include <iostream>

int main()

{

    boost::gregorian::date d(boost::gregorian::day_clock::local_day());

    std::cout << d.year() << d.month() <<d.day() << std::endl;

}

編譯運行

g++ -I /usr/local/boost/include -L /usr/local/boost/lib boost.cpp -o boost
 ./boost
2015Jul9

若測試報錯,請查看 http://blog.csdn.net/abcd1f2/article/details/49777715

#############################################

五,安裝cmake

下載 https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz  ,上傳

解壓:ta  -zxvf  cmake-3.7.2.tar.gz  ;  cd cmake-3.7.2;

      1)   ./bootstrap
      2)   gmake
      3)   sudo gmake install
      4)  [wgl@wgl bin]$ sudo ln -s /usr/local/bin/cmake  /usr/bin/cmake
          [wgl@wgl bin]$ sudo ln -s /usr/local/bin/cpack  /usr/bin/cpack
          [wgl@wgl bin]$ sudo ln -s /usr/local/bin/ctest  /usr/bin/ctest 

#############################################

六,安裝  BLAS

(1)下載 http://www.openblas.net/ 

(2)解壓:tar -zxvf OpenBLAS-0.2.19.tar.gz ; cd OpenBLAS-0.2.19;

(3)添加  #define NO_AVX2 1024  到 cpuid.h 文件的倒數第2行  

(4)sudo make (make TARGET=NEHALEM)   若報一下錯誤,參考下面解決辦法 

  

 sudo ln -s /usr/lib64/libgfortran.so.3.0.0  /usr/lib64/libgfortran.so

 http://blog.csdn.net/yasi_xi/article/details/8658191

(5)sudo make  install

#############################################

七,安裝python的包管理工具

1、安裝pip前須要前置安裝setuptools

unzip setuptools-36.0.1.zip
cd setuptools-36.0.1
sudo python setup.py build
sudo python setup.py install

報錯: RuntimeError: Compression requires the (missing) zlib module

咱們須要在linux中安裝zlib-devel包,進行支持。

yum install zlib-devel

須要對python2.7進行從新編譯安裝。

cd Python-2.7.8

sudo make

sudo make install

從新安裝setuptools

sudo python setup.py build

sudo python setup.py install

2、安裝pip

tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1
sudo python setup.py build
sudo python setup.py install

若是沒有意外的話,pip安裝完成。

創建軟鏈接

ln -s /usr/local/python27/bin/pip /usr/bin/pip
ln -s /usr/local/python27/bin/pip2 /usr/bin/pip2
ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip2.7
ln -s /usr/local/python27/bin/easy_install /usr/bin/easy_install
ln -s /usr/local/python27/bin/easy_install-2.7 /usr/bin/easy_install-2.7

正式安裝python模塊

#############################################

(1)安裝dlib     https://pypi.python.org/pypi/dlib          dlib-19.4.0.tar.gz

sudo pip install  dlib-19.4.0.tar.gz     

OK  (sudo yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r))

測試:導入模塊

若報錯,解決:

找到 libopenblas.so.0所在路徑:/opt/OpenBLAS/lib

sudo vi /etc/ld.so.conf   添加一行/opt/OpenBLAS/lib
sudo  /sbin/ldconfig -v

若報錯:

linux-wgl:~ # python
Python 2.7.8 (default, Sep 13 2017, 16:30:53) 
[GCC 4.9.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python27/lib/python2.7/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: /usr/lib64/libboost_python.so.1.36.0: undefined symbol: PyUnicodeUCS4_FromEncodedObject
>>>

解決:將boost的lib下的libboost_python.so替換/usr/lib64下的。

**************************************************************

(2)安裝numpy   https://pypi.python.org/pypi/numpy

sudo pip install numpy-1.13.1-cp27-cp27m-manylinux1_x86_64.whl

################################################

(3)安裝scipy    https://pypi.python.org/pypi/scipy

sudo pip install scipy-0.19.1-cp27-cp27m-manylinux1_x86_64.whl

################################################

(4)安裝matplotlib  https://pypi.python.org/pypi/matplotlib

sudo pip install matplotlib-2.0.2-cp27-cp27m-manylinux1_x86_64.whl

(因缺乏依賴,先安裝依賴,可根據報錯信息查找依賴,下載包,安裝)

如:依賴cycler>=0.10

下載地址https://pypi.python.org/pypi/XXX(xxx爲缺乏的組件)

https://pypi.python.org/pypi/cycler                   

sudo pip install cycler-0.10.0-py2.py3-none-any.whl

https://pypi.python.org/pypi/six 

sudo pip install six-1.10.0-py2.py3-none-any.whl

https://pypi.python.org/pypi/pyparsing 

sudo pip install pyparsing-2.2.0-py2.py3-none-any.whl

https://pypi.python.org/pypi/subprocess32      

sudo pip install subprocess32-3.2.7.tar.gz

若報錯:

解決辦法:

1,tar -zxvf  subprocess32-3.2.7.tar.gz

2,cd subprocess32-3.2.7

3,將libpython2.7.so拷貝到當前目錄下

4,python setup.py build

5,python setup.py install

 

https://pypi.python.org/pypi/functools32        

 sudo pip install functools32-3.2.3-2.tar.gz

https://pypi.python.org/pypi/python-dateutil

 sudo pip install python_dateutil-2.6.1-py2.py3-none-any.whl          

https://pypi.python.org/pypi/pytz

 sudo pip install pytz-2017.2-py2.py3-none-any.whl

################################################

(5)安裝skimage    https://pypi.python.org/pypi/scikit-image

sudo pip install scikit_image-0.13.0-cp27-cp27m-manylinux1_x86_64.whl

(因缺乏依賴,先安裝依賴,可根據報錯信息查找依賴,下載包,安裝)

https://pypi.python.org/pypi/PyWavelets

 sudo pip install PyWavelets-0.5.2-cp27-cp27m-manylinux1_x86_64.whl

https://pypi.python.org/pypi/PyYAML               

sudo pip install PyYAML-3.12.tar.gz

https://pypi.python.org/pypi/networkx               

sudo pip install networkx-1.11-py2.py3-none-any.whl

https://pypi.python.org/pypi/decorator              

sudo pip install decorator-4.0.11-py2.py3-none-any.whl   

https://pypi.python.org/pypi/pillow

sudo pip install Pillow-4.2.1-cp27-cp27m-manylinux1_x86_64.whl 

https://pypi.python.org/pypi/olefile                   

sudo pip install olefile-0.44.zip

################################################
(6)安裝imtools

https://pypi.python.org/pypi/imtools

sudo pip install imtools-0.1.11.tar.gz     

################################################

所有完成:

 ###############################################

可能優化:

一、CUDA安裝 
官方下載:https://developer.nvidia.com/cuda-downloads

sudo rpm -i cuda-repo-rhel7-8.0.44-1.x86_64.rpm

sudo yum clean all

sudo yum install cuda

sudo rpm -ihv libvdpau-0.9-1.el6.x86_64.rpm

sudo rpm -ihv dkms-2.1.1.2-1.el6.rf.noarch.rpm --nodeps

二、cuDNN安裝

官網下載:https://developer.nvidia.com/rdp/cudnn-download

而後把lib文件加入到系統能找到的lib文件夾裏, 把頭文件加到系統能找到的include文件夾裏就能夠。這裏把他們加到CUDA的文件夾下。

tar -zxf cudnn-7.5-linux-x64-v5.0-ga.tgz

cd cuda

sudo cp -P lib64/* /usr/local/cuda/lib64/

sudo cp -P include/* /usr/local/cuda/include/

sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

#########################################################

相關文章
相關標籤/搜索