win7环境下安装dlib人脸检测包

背景

项目中需要用到dlib包进行人脸检测与关键点提取,之前都是在mac或者linux系统下进行的,这次需要在Windows系统下进行。在mac或者linux系统下,安装非常简单,使用以下命令即可

pip install dlib

但是在Windows系统下使用这个命令会报错:

Collecting dlib
  Downloading https://files.pythonhosted.org/packages/05/57/e8a8caa3c89a27f80bc78da39c423e2553f482a3705adc619176a3a24b36/dlib-19.17.0.tar.gz (3.4MB)
     |████████████████████████████████| 3.4MB 14kB/s
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Complete output from command 'f:\python36\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\fu\\AppData\\Local\\Temp\\pip-install-t50q34ym\\dlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\fu\AppData\Local\Temp\pip-wheel-g2i4oztb' --python-tag cp36:
  ERROR: running bdist_wheel
  running build
  running build_py
  package init file 'dlib\__init__.py' not found (or not a regular file)
  running build_ext
  Traceback (most recent call last):
    File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 120, in get_cmake_version
      out = subprocess.check_output(['cmake', '--version'])
    File "f:\python36\lib\subprocess.py", line 356, in check_output
      **kwargs).stdout
    File "f:\python36\lib\subprocess.py", line 423, in run
      with Popen(*popenargs, **kwargs) as process:
    File "f:\python36\lib\subprocess.py", line 729, in __init__
      restore_signals, start_new_session)
    File "f:\python36\lib\subprocess.py", line 1017, in _execute_child
      startupinfo)
  FileNotFoundError: [WinError 2] 系统找不到指定的文件。

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 261, in <module>
      'Topic :: Software Development',
    File "f:\python36\lib\site-packages\setuptools\__init__.py", line 143, in setup
      return distutils.core.setup(**attrs)
    File "f:\python36\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "f:\python36\lib\distutils\dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "f:\python36\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "f:\python36\lib\site-packages\wheel\bdist_wheel.py", line 192, in run
      self.run_command('build')
    File "f:\python36\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "f:\python36\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "f:\python36\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "f:\python36\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "f:\python36\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 129, in run
      cmake_version = self.get_cmake_version()
    File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 125, in get_cmake_version
      "\n*******************************************************************\n")
  RuntimeError:
  *******************************************************************
   CMake must be installed to build the following extensions: dlib
  *******************************************************************

  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib
  Running setup.py install for dlib ... error
    ERROR: Complete output from command 'f:\python36\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\fu\\AppData\\Local\\Temp\\pip-install-t50q34ym\\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 'C:\Users\fu\AppData\Local\Temp\pip-record-4kwg7hfv\install-record.txt' --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    running build_ext
    Traceback (most recent call last):
      File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 120, in get_cmake_version
        out = subprocess.check_output(['cmake', '--version'])
      File "f:\python36\lib\subprocess.py", line 356, in check_output
        **kwargs).stdout
      File "f:\python36\lib\subprocess.py", line 423, in run
        with Popen(*popenargs, **kwargs) as process:
      File "f:\python36\lib\subprocess.py", line 729, in __init__
        restore_signals, start_new_session)
      File "f:\python36\lib\subprocess.py", line 1017, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] 系统找不到指定的文件。

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 261, in <module>
        'Topic :: Software Development',
      File "f:\python36\lib\site-packages\setuptools\__init__.py", line 143, in setup
        return distutils.core.setup(**attrs)
      File "f:\python36\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "f:\python36\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "f:\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "f:\python36\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "f:\python36\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "f:\python36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "f:\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "f:\python36\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "f:\python36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "f:\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 129, in run
        cmake_version = self.get_cmake_version()
      File "C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\setup.py", line 125, in get_cmake_version
        "\n*******************************************************************\n")
    RuntimeError:
    *******************************************************************
     CMake must be installed to build the following extensions: dlib
    *******************************************************************

    ----------------------------------------
ERROR: Command "'f:\python36\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\fu\\AppData\\Local\\Temp\\pip-install-t50q34ym\\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 'C:\Users\fu\AppData\Local\Temp\pip-record-4kwg7hfv\install-record.txt' --single-version-externally-managed --compile" failed with error code 1 in C:\Users\fu\AppData\Local\Temp\pip-install-t50q34ym\dlib\
WARNING: You are using pip version 19.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

原因是由于dlib需要使用c++进行编译,让你首先安装cmake

解决方法

  • 方法一: 非常费劲
Step 1: Install Visual Studio 2015
Step 2: Install CMake v3.8.2
Step 3: Install Anaconda 3
Step 4: Download Dlib
Step 5: Build Dlib library
Step 6: Update user environment variable – dlib_DIR
---
具体参考:https://www.learnopencv.com/install-dlib-on-windows/

  • 方法二: 安装dlib前需要先安装cmake 和boost。然后才能正确安装dlib
pip install boost
pip install cmake
pip install dib
  • 方法三:通过对应版本的dlib的whl文件进行安装

whl格式本质上是一个压缩包,里面包含了py文件,以及经过编译的pyd文件。使得可以在不具备编译环境的情况下,选择合适自己的python环境进行安装。
安装方法很简单,进入命令行输入

pip install xxxx.whl

或者如果是升级

pip install -U xxxx.whl

这里我们使用以下命令进行安装,前提是下载对应文件,跳转到对应的文件夹下:

pip install dlib-19.17.99-cp37-cp37m-win_amd64.whl

whl文件下载地址
链接: https://pan.baidu.com/s/1MKqW7WH2XP-J8MOLeq3cDA
提取码: rfh8

参考:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

uncle_ll

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值