在Python27中运行pip install dlib装载库dlib所引起的问题解决

来源:互联网 发布:关于贼的网络用语 编辑:程序博客网 时间:2024/05/14 11:36
看人脸方面的资料的时候,会发现很多人都会提到dlib这个库,于是就安装尝试下这个库看看它到底有多么的神奇。今天只是初次尝试一下dlib到底怎么用。
可是在安装这个库的时候遇到一堆问题:最初是没有Cmake编译器,这个好解决,cmake都是自动安装配置的。最大的问题如下所出现的,没有发现boost库:  
-- Could NOT find Boost
于是乎,编译Boost库成了首要问题。


D:\Program Files\Python\Python27>pip install dlib
Collecting dlib
  Using cached dlib-19.1.0.tar.gz
Installing collected packages: dlib
  Running setup.py install for dlib ... error
    Complete output from command "d:\program files\python\python27\python.exe" -
u -c "import setuptools, tokenize;__file__='d:\\downlo~1\\system~1\\pip-build-a2
eyii\\dlib\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().
replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install -
-record d:\downlo~1\system~1\pip-teyh4o-record\install-record.txt --single-versi
on-externally-managed --compile:
    running install
    running build
    Detected Python architecture: 32bit
    Detected platform: win32
    Configuring cmake ...
    -- Building for: Visual Studio 10 2010
    -- The C compiler identification is MSVC 16.0.30319.1
    -- The CXX compiler identification is MSVC 16.0.30319.1
    -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Stu
dio 10.0/VC/bin/cl.exe
    -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Stu
dio 10.0/VC/bin/cl.exe -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual S
tudio 10.0/VC/bin/cl.exe
    -- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual S
tudio 10.0/VC/bin/cl.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    CMake Warning at D:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cm
ake:744 (message):
      Imported targets not available for Boost version 106300
    Call Stack (most recent call first):
      D:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost
_COMPONENT_DEPENDENCIES)
      D:/Program Files/CMake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boos
t_MISSING_DEPENDENCIES)
      D:/Downloads/SystemTemp/pip-build-a2eyii/dlib/dlib/cmake_utils/add_python_
module:73 (FIND_PACKAGE)
      CMakeLists.txt:6 (include)
    -- Could NOT find Boost
    -- Found PythonLibs: D:/Program Files/Python/Python27/libs/python27.lib (fou
nd suitable version "2.7.12", minimum required is "2.6")
    --  ************************************************************************
*****************************
    -- We couldn't find the right version of boost python.  If you installed boo
st and you are still getting this error then you might have installed a version
of boost that was compiled with a different version of visual studio than the on
e you are using.  So you have to make sure that the version of visual studio is
the same version that was used to compile the copy of boost you are using.
    --  Set the BOOST_ROOT and BOOST_LIBRARYDIR environment variables before run
ning cmake.
    --  E.g.  Something like this:
    --     set BOOST_ROOT=C:\local\boost_1_57_0
    --     set BOOST_LIBRARYDIR=C:\local\boost_1_57_0\stage\lib
    --
    --  You will also likely need to compile boost yourself rather than using on
e of the precompiled
    --  windows binaries.  Do this by going to the folder tools\build\ within bo
ost and running
    --  bootstrap.bat.  Then run the command:
    --     b2 install
    --  And then add the output bin folder to your PATH.  Usually this is the C:
\boost-build-engine\bin
    --  folder. Finally, go to the boost root and run a command like this:
    --     b2 -a --with-python address-model=64 toolset=msvc runtime-link=static


    --  When it completes, set BOOST_LIBRARYDIR equal to wherever b2 put the com
piled libraries.
    --  Note that you will need to set the address-model based on if you want a
32 or 64bit python library.
    --
    --  Next, when you invoke cmake to compile dlib you may have to use cmake's
-G option to set the
    --  64 vs. 32bit mode of visual studio.  Also, if you want a Python3 library
 you will need to
    --  add -DPYTHON3=1.  You do this with a statement like:
    --     cmake -G "Visual Studio 12 2013 Win64" -DPYTHON3=1 ..\..\tools\python


    --  Rather than:
    --     cmake ..\..\tools\python
    --  Which will build a 32bit Python2 module by default on most systems.
    --
    --  ************************************************************************
*****************************
    CMake Error at D:/Downloads/SystemTemp/pip-build-a2eyii/dlib/dlib/cmake_util
s/add_python_module:115 (message):
       Boost python library not found.
    Call Stack (most recent call first):
      CMakeLists.txt:6 (include)
    -- Configuring incomplete, errors occurred!
    See also "D:/Downloads/SystemTemp/pip-build-a2eyii/dlib/tools/python/build/C
MakeFiles/CMakeOutput.log".
    error: cmake configuration failed!


    ----------------------------------------
Command ""d:\program files\python\python27\python.exe" -u -c "import setuptools,
 tokenize;__file__='d:\\downlo~1\\system~1\\pip-build-a2eyii\\dlib\\setup.py';f=
getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.
close();exec(compile(code, __file__, 'exec'))" install --record d:\downlo~1\syst
em~1\pip-teyh4o-record\install-record.txt --single-version-externally-managed --
compile" failed with error code 1 in d:\downlo~1\system~1\pip-build-a2eyii\dlib\




D:\Program Files\Python\Python27>


首先下载boost库,根据提示:
1)运行 bootstrap.bat.  生成三个文件,其中包括b2
  --  bootstrap.bat
2)运行b2
  --     b2 install
3) 利用b2编译库文件
 --     b2 -a --with-python address-model=64 toolset=msvc runtime-link=static
这里遇到些问题, address-model=64参数设置出现问题,后改成32则成功。
4)设置变量
    --     set BOOST_ROOT=C:\local\boost_1_57_0
    --     set BOOST_LIBRARYDIR=C:\local\boost_1_57_0\stage\lib
将这两个变量设置到到Path变量中: %BOOST_ROOT%;%BOOST_LIBRARYDIR%
5)然后运行pip install dlib
成功
D:\Program Files\Python\Python27>pip install dlib
Collecting dlib
Using cached dlib-19.1.0.tar.gz
Installing collected packages: dlib
Running setup.py install for dlib ... done
Successfully installed dlib-19.1.0


D:\Program Files\Python\Python27>
0 1