如何解决必须安装 CMake 才能构建以下扩展:PyCharm 中的 dlib?

Posted

技术标签:

【中文标题】如何解决必须安装 CMake 才能构建以下扩展:PyCharm 中的 dlib?【英文标题】:How to solve CMake must be installed to build the following extensions: dlib in PyCharm? 【发布时间】:2021-09-08 12:47:39 【问题描述】:

为 OpenCV 项目安装 dlib 时遇到以下错误。这表明

必须安装 CMake 才能构建以下扩展:dlib。

命令输出:

Collecting dlib==19.18.0
  Using cached dlib-19.18.0.tar.gz (3.1 MB)
Using legacy 'setup.py install' for dlib, since package 'wheel' is not installed.
Installing collected packages: dlib
    Running setup.py install for dlib: started
    Running setup.py install for dlib: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: 'D:\Install Drive\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\mahmu\\AppData\\Local\\Temp\\pip-install-a4s1a_zh\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\mahmu\\AppData\\Local\\Temp\\pip-install-a4s1a_zh\\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\mahmu\AppData\Local\Temp\pip-record-mjm6k3c3\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Install Drive\Include\dlib'
         cwd: C:\Users\mahmu\AppData\Local\Temp\pip-install-a4s1a_zh\dlib\
    Complete output (57 lines):
    running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    warning: build_py: byte-compiling is disabled, skipping.
    
    running build_ext
    Traceback (most recent call last):
      File "C:\Users\mahmu\AppData\Local\Temp\pip-install-a4s1a_zh\dlib\setup.py", line 120, in get_cmake_version
        out = subprocess.check_output(['cmake', '--version'])
      File "D:\Install Drive\lib\subprocess.py", line 424, in check_output
        return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
      File "D:\Install Drive\lib\subprocess.py", line 505, in run
        with Popen(*popenargs, **kwargs) as process:
      File "D:\Install Drive\lib\subprocess.py", line 951, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "D:\Install Drive\lib\subprocess.py", line 1420, in _execute_child
        hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
    FileNotFoundError: [WinError 2] The system cannot find the file specified
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\mahmu\AppData\Local\Temp\pip-install-a4s1a_zh\dlib\setup.py", line 223, in <module>
        setup(
      File "D:\Install Drive\lib\site-packages\setuptools\__init__.py", line 165, in setup
        return distutils.core.setup(**attrs)
      File "D:\Install Drive\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "D:\Install Drive\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "D:\Install Drive\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "D:\Install Drive\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "D:\Install Drive\lib\distutils\command\install.py", line 546, in run
        self.run_command('build')
      File "D:\Install Drive\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "D:\Install Drive\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "D:\Install Drive\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "D:\Install Drive\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "D:\Install Drive\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\mahmu\AppData\Local\Temp\pip-install-a4s1a_zh\dlib\setup.py", line 129, in run
        cmake_version = self.get_cmake_version()
      File "C:\Users\mahmu\AppData\Local\Temp\pip-install-a4s1a_zh\dlib\setup.py", line 122, in get_cmake_version
        raise RuntimeError("\n*******************************************************************\n" +
    RuntimeError:
    *******************************************************************
     CMake must be installed to build the following extensions: dlib
    *******************************************************************
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\Install Drive\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\mahmu\\AppData\\Local\\Temp\\pip-install-a4s1a_zh\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\mahmu\\AppData\\Local\\Temp\\pip-install-a4s1a_zh\\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\mahmu\AppData\Local\Temp\pip-record-mjm6k3c3\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Install Drive\Include\dlib' Check the logs for full command output.
WARNING: You are using pip version 20.2.3; however, version 21.1.2 is available.
You should consider upgrading via the 'D:\Install Drive\python.exe -m pip install --upgrade pip' command.

【问题讨论】:

它还说:“必须安装 CMake 才能构建以下扩展:dlib”。你有安装 CMake 吗? 如果答案解决了您的问题,请不要忘记在答案左侧accept it by clicking the green check mark。 【参考方案1】:

请注意,在输出中“必须安装 CMake 才能构建以下扩展:dlib”。所以先安装 CMake,然后再尝试安装 dlib。如果安装了 CMake,请尝试通过“D:\Install Drive\python.exe -m pip install --upgrade pip”将您的 pip 版本更新到 21.1.2。

【讨论】:

以上是关于如何解决必须安装 CMake 才能构建以下扩展:PyCharm 中的 dlib?的主要内容,如果未能解决你的问题,请参考以下文章

CMake 学习四:CMake 构建静态库和动态库

Python face_recognition 无法安装

QtCreator 无法识别 cmake

cmake

如何构建 CMake 项目

如何独立于标准启用 GCC 的 GNU 扩展?