之前一直想安装在win10笔记本上,但是一直碰壁,碰的我头痛。
然后想试一下在各种云服务器上,更是碰壁。
碰壁的主要原因是dlib安装不上,是真的带不动,各种问题。
然后索性之前还装了virtual-box,里面有一个ubuntu系统。
所以就按照找好了的教程一步一步装,果然好了!真的是皇天不负有心人!
主要是根据这个教程写的,我直接粘过来吧。
1、安装步骤参见:
https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf
用git clone dlib库:git clone https://github.com/davisking/dlib.git
进入dlib目录:cd dlib
执行:mkdir build,创建build目录
进入dlib/build目录: cd build
执行:cmake …
执行:cmake --build .
编译完成后,回到dlib目录:
cd …
执行:python3 setup.py install (这里注意,如果是python2.x,请用python setup.py install)
2、用cmake进行编译安装,如过没有cmake,记得安装,最好是3.x以上,如果cmake版本是2.x的记得卸载后升级到3.x,因为isuse上说,最好是用3.x以上的cmake
3、当你执行到 python3 setup.py install 这一步时(我的环境是python2.7 ,用的是python setup.py install),可能会出现一下错误:
Java代码 收藏代码
译中断。
In file included from /usr/local/dlib/dlib/external/pybind11/include/pybind11/pytypes.h:12:0,
from /usr/local/dlib/dlib/external/pybind11/include/pybind11/cast.h:13,
from /usr/local/dlib/dlib/external/pybind11/include/pybind11/attr.h:13,
from /usr/local/dlib/dlib/external/pybind11/include/pybind11/pybind11.h:43,
from /usr/local/dlib/dlib/../dlib/python/pybind_utils.h:6,
from /usr/local/dlib/dlib/../dlib/python.h:6,
from /usr/local/dlib/tools/python/src/opaque_types.h:6,
from /usr/local/dlib/tools/python/src/svm_c_trainer.cpp:4:
/usr/local/dlib/dlib/external/pybind11/include/pybind11/detail/common.h:111:20: 致命错误:Python.h:没有那个文件或目录
#include <Python.h>
^
编译中断。
gmake[2]: *** [CMakeFiles/dlib_python.dir/src/dlib.cpp.o] 错误 1
gmake[2]: *** 正在等待未完成的任务....
gmake[2]: *** [CMakeFiles/dlib_python.dir/src/vector.cpp.o] 错误 1
gmake[2]: *** [CMakeFiles/dlib_python.dir/src/svm_c_trainer.cpp.o] 错误 1
gmake[2]: *** [CMakeFiles/dlib_python.dir/src/matrix.cpp.o] 错误 1
gmake[1]: *** [CMakeFiles/dlib_python.dir/all] 错误 2
gmake: *** [all] 错误 2
Traceback (most recent call last):
File "setup.py", line 261, in <module>
'Topic :: Software Development',
File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 73, in run
self.do_egg_install()
File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 93, in do_egg_install
self.run_command('bdist_egg')
File "/usr/lib64/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/site-packages/setuptools/command/bdist_egg.py", line 185, in run
cmd = self.call_command('install_lib', warn_dir=0)
File "/usr/lib/python2.7/site-packages/setuptools/command/bdist_egg.py", line 171, in call_command
self.run_command(cmdname)
File "/usr/lib64/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/site-packages/setuptools/command/install_lib.py", line 20, in run
self.build()
File "/usr/lib64/python2.7/distutils/command/install_lib.py", line 111, in build
self.run_command('build_ext')
File "/usr/lib64/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 135, in run
self.build_extension(ext)
File "setup.py", line 175, in build_extension
subprocess.check_call(cmake_build, cwd=build_folder)
File "/usr/lib64/python2.7/subprocess.py", line 542, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '-j4']' returned non-zero exit status 2
这时,安装yum install python-devel,可以解决上述问题。
(注意这里可以不用yum,而是用下面这个)
👇
用aptitude 工具可以搞定
先:sudo apt-get install aptitude
然后:
sudo aptitude install python-dev
至此,终于安装完成。