Linux Install Python dlib dependent

Source: Internet
Author: User

Dlib is mainly used in machine learning Library, encapsulating the machine learning algorithm, can be very convenient to implement such as face recognition, vehicle identification, object detection with many other functions, dlib by default use C + + for development, the other image recognition has a part of the support of Python interface development, get started very fast, Because of the installation process of the system, all from the official document piece, the online information is very few, the novice will have some pits, so here is the main point of the Python interface installation, server environment Centos7.3,python version 2.7, the following are all dependencies and installation order:

1. Pip python module,: Https://pypi.python.org/pypi/pip

2. CMake compile tool before the article has detailed installation procedure

3. Boost.python Boost is a popular C + + class library that encapsulates a number of useful tools, Boost.python one of the components, mainly encapsulates the API for communication between Python and C/s + +, and is more complete than the default Python API. Dlib is based on this dependency, so it needs to compile Boost.python dependency

4. Dlib python module, the front environment is ready, the final step is to compile and install the Dlib python extension

When the Dlib Python module executes the installation, the process compiles the Dlib source code based on the CMake compilation tool and Boost.python tool, compiles the binary module into the Python Library directory, and then Python can call it, starting with the installation

1. PIP module

PIP module downloaded from the above URL, unzip open, directly execute Python setup.py install, and normal module installation, nothing to say

2. CMake Compilation Tool

Refer to the previous article http://www.cnblogs.com/freeweb/p/5788729.html installation, if you do not have a cmake module, you will be prompted when installing Dlib

3. Boost.python

If there is no boost python dependency, then the next step in compiling dlib will be to give explicit hints and steps, as follows:

  

Steps are actually given out, so follow the above steps to install, the following is the specific process:

3.1. Download the Boost library

Boost official website: http://www.boost.org/, click on the right of the latest version of the download can:

  

I download here: boost_1_65_1.tar.bz2 size 80M or so

3.2. Install the Boost library

To start the installation after downloading, first unpack the installation package:

tar -jxvf boost_1_65_1. Tar . BZ2CD Boost_1_65_1/

Then follow the steps in the picture above and the official website documentation to install:

./bootstrap. sh --prefix=/monchickey/boost--with-libraries=python. /B2. Install

The above parameters:--prefix is the location of the specified installation, if not the default is installed in the/usr/local and the system library mix, so it is easier later, but if you manually specify the directory so easy to manage the library, but later to configure some things, the following will be said The--with-libraries=python must be added, otherwise the Python module will not be compiled, or the--with-python and the--with-python=python3 parameters for Python3 are used. The above installation process will take a long time, after installation into the installation directory, you will see only two directories, one is include mainly the header files and source code files, and the other is LIB, which is our compiled Python-related dependencies, as follows:

  

Boost.python relies on this, even if the installation is complete.

4. Finally compile the Dlib python module

Dlib Library website address: http://dlib.net/ml.html Enter and click on the lower left side button to download directly:

  

Here is the download: dlib-19.7.tar.bz2, first in the specified location decompression:

tar -jxvf dlib-19.7. Tar . BZ2CD dlib-19.7/

Enter the directory will see setup.py, if the above Boost.python installed in the system directory, then the immediate installation should be able, if it is a custom directory, this time the installation will still error prompts to find the Boost Python library, In fact, CMake can not find boost, it is not urgent to configure the system library to build a soft chain, but to configure the environment variables, the purpose is to let CMake find Boost, first execute vim/etc/profile and then in the last line plus: Export Boost_root=/monchickey/boost Specify the BOOST root directory as follows:

  

Once configured, execute source/etc/profile to make the environment variable effective, and you can then perform the installation:

Install --yes use_avx_instructions

This parameter is added here to support the CPU AVX instruction set, which can improve the performance of the program running, the current general CPU support; the installation is complete after the installation is complete, run python into the interactive interface, enter import dlib If normal, but if the boost library is not installed in the default directory, the problem will still be libboost_ Python.so can not find the error, because the import compiled Dlib module, while Dlib runtime will also load Boost.python library, this time the system search is not so will error, this and just cmake error is different, do not put just the boost library files under the Python library, Only libraries compiled to be directly called by Python are placed under the Python directory, and the C-based Python library, which relies on the system library search path, should be/usr/lib,/usr/lib64, so there are two ways to solve this problem:

1). Create a soft link to the so module in/monchickey/boost/lib to the/usr/lib64 below

2). Load a new library search path with the configuration file/etc/ld.so.conf

Using the second method, first execute the vim/etc/ld. so.conf.d/boost.conf Create a new configuration file, and then add a line:/monchickey/boost/lib Save and exit,

Then execute the command: ldconfig the configuration into effect so that the specified link library is added to the runtime search directory

Now it's normal to import the Dlib module again.

Linux Install Python dlib dependent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.