SUSE Linux Enterprise 11 离线安装 DLIB 人脸识别 python机器学习模块

python机器学习模块安装

我的博客:http://www.cnblogs.com/wglIT/p/7525046.html

 

环境:SUSE Linux Enterprise 11 sp4  离线安装

说明:在安装dlib时依赖的基础 环境较多,先升级gcc,以适应c++ 11的使用;需要用到cmake编译工具,boost这个c++库,BLAS。python升级到2.7以上版本。

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

一,安装相关依赖包 

安装部分依赖:

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包,手动安装相关依赖

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  

参考: 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     

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

全部完成:

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

可能优化:

1、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

2、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*

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

转载于:https://www.cnblogs.com/wglIT/p/7525046.html

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页