如何解决 Dlib Visual Studios C++ 错误?

Posted

技术标签:

【中文标题】如何解决 Dlib Visual Studios C++ 错误?【英文标题】:how to solve Dlib visual studios c++ error? 【发布时间】:2021-05-30 14:54:47 【问题描述】:
C:\Users\User_01>pip install dlib
Defaulting to user installation because normal site-packages is not writeable
Collecting dlib
  Using cached dlib-19.21.1.tar.gz (3.6 MB)
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\program files\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\setup.py'"'"'; __file__='"'"'C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\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\User_01\AppData\Local\Temp\pip-wheel-u114ylxx'
       cwd: C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\
  Complete output (58 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'tools\python\dlib\__init__.py' not found (or not a regular file)
  running build_ext
  Building extension for Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)]
  Invoking CMake setup: 'cmake C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\build\lib.win-amd64-3.8 -DPYTHON_EXECUTABLE=c:\program files\python38\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\build\lib.win-amd64-3.8 -A x64'
  -- Building for: NMake Makefiles
  CMake Error at CMakeLists.txt:5 (message):



    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    You must use Visual Studio to build a python extension on windows.  If you
    are getting this error it means you have not installed Visual C++.  Note
    that there are many flavors of Visual Studio, like Visual Studio for C#
    development.  You need to install Visual Studio for C++.


    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




  -- Configuring incomplete, errors occurred!
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\setup.py", line 223, in <module>
      setup(
    File "c:\program files\python38\lib\site-packages\setuptools\__init__.py", line 165, in setup
      return distutils.core.setup(**attrs)
    File "c:\program files\python38\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "c:\program files\python38\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "c:\program files\python38\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\User_01\AppData\Roaming\Python\Python38\site-packages\wheel\bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "c:\program files\python38\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\program files\python38\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "c:\program files\python38\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "c:\program files\python38\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\program files\python38\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\setup.py", line 135, in run
      self.build_extension(ext)
    File "C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\setup.py", line 172, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "c:\program files\python38\lib\subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\build\\lib.win-amd64-3.8', '-DPYTHON_EXECUTABLE=c:\\program files\\python38\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\build\\lib.win-amd64-3.8', '-A', 'x64']' returned non-zero exit status 1.
  ----------------------------------------
  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: Command errored out with exit status 1:
     command: 'c:\program files\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\setup.py'"'"'; __file__='"'"'C:\\Users\\User_01\\AppData\\Local\\Temp\\pip-install-trf2srgw\\dlib_042210a71f3f4d22994c8640d6338561\\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\User_01\AppData\Local\Temp\pip-record-7k2ytc23\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\User_01\AppData\Roaming\Python\Python38\Include\dlib'
         cwd: C:\Users\User_01\AppData\Local\Temp\pip-install-trf2srgw\dlib_042210a71f3f4d22994c8640d6338561\

尝试使用 pip pip install dlib 安装 dlib 时出现此错误。 这个错误说

------------------------------------------------------------------------------
You must use Visual Studio to build a python extension on windows.  If you
are getting this error it means you have not installed Visual C++.  Note
that there are many flavors of Visual Studio, like Visual Studio for C#
development.  You need to install Visual Studio for C++.
------------------------------------------------------------------------------

【问题讨论】:

【参考方案1】:

我找到了答案下载并安装 Visual Studios C++ 构建工具,它会工作。 然后在控制台上运行 pip pip install dlib

下载 Visual Studio 构建工具 - https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16

【讨论】:

以上是关于如何解决 Dlib Visual Studios C++ 错误?的主要内容,如果未能解决你的问题,请参考以下文章

GLEW 无法在 Visual Studios 2010 中工作

Visual Studios 调试设置保存在哪里?

C++如何限制visual studios多处理器编译

Visual Studios 2012 更改运行时库会导致链接错误,使用 C++

由于找不到文件错误,无法在 Visual Studios 中运行 C++ 代码 [重复]

错误:名称在当前上下文中不存在(Webpart、C#、Visual Studios、SharePoint 2010)