错误在Jupyter Notebook下安装Python dlib。

huangapple go评论113阅读模式
英文:

Error installing python dlib uder jupyrer notebook

问题

在Jupyter Notebook下,我尝试安装dlib包:

  1. pip install dlib

我收到了以下错误:

  1. Collecting dlib
  2. Using cached dlib-19.24.2.tar.gz (11.8 MB)
  3. Installing build dependencies: started
  4. Installing build dependencies: finished with status 'done'
  5. Getting requirements to build wheel: started
  6. Getting requirements to build wheel: finished with status 'done'
  7. Preparing metadata (pyproject.toml): started
  8. Preparing metadata (pyproject.toml): finished with status 'done'
  9. Building wheels for collected packages: dlib
  10. Building wheel for dlib (pyproject.toml): started
  11. Building wheel for dlib (pyproject.toml): finished with status 'error'
  12. Failed to build dlib
  13. error: subprocess-exited-with-error
  14. ...
  15. ERROR: Failed building wheel for dlib

我不理解这个错误,cmake已经安装。

  1. import sys
  2. print(sys.version)
  3. 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)]

看起来错误来自cmake的安装,当在命令行中尝试运行cmake --version命令时,编译器无法识别该命令:

  1. 'cmake' is not recognized as an internal or external command,
  2. operable program or batch file.
英文:

Under Jupiter notebook, i tried to install dlib package :

  1. pip install dlib

I obtained the following error :

  1. Collecting dlib
  2. Using cached dlib-19.24.2.tar.gz (11.8 MB)
  3. Installing build dependencies: started
  4. Installing build dependencies: finished with status 'done'
  5. Getting requirements to build wheel: started
  6. Getting requirements to build wheel: finished with status 'done'
  7. Preparing metadata (pyproject.toml): started
  8. Preparing metadata (pyproject.toml): finished with status 'done'
  9. Building wheels for collected packages: dlib
  10. Building wheel for dlib (pyproject.toml): started
  11. Building wheel for dlib (pyproject.toml): finished with status 'error'
  12. Failed to build dlib
  13. error: subprocess-exited-with-error
  14. Building wheel for dlib (pyproject.toml) did not run successfully.
  15. exit code: 1
  16. [73 lines of output]
  17. running bdist_wheel
  18. running build
  19. running build_ext
  20. <string>:125: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  21. Building extension for Python 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)]
  22. Invoking CMake setup: 'cmake C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-install-s4im1wse\dlib_6311ea7c12944928afe6fa5cda1f5d5d\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-install-s4im1wse\dlib_6311ea7c12944928afe6fa5cda1f5d5d\build\lib.win-amd64-cpython-310 -DPYTHON_EXECUTABLE=C:\Users\Rayane_2\AppData\Local\r-miniconda\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-install-s4im1wse\dlib_6311ea7c12944928afe6fa5cda1f5d5d\build\lib.win-amd64-cpython-310 -A x64'
  23. -- Building for: NMake Makefiles
  24. CMake Error at CMakeLists.txt:5 (message):
  25. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  26. You must use Visual Studio to build a python extension on windows. If you
  27. are getting this error it means you have not installed Visual C++. Note
  28. that there are many flavors of Visual Studio, like Visual Studio for C#
  29. development. You need to install Visual Studio for C++.
  30. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  31. -- Configuring incomplete, errors occurred!
  32. Traceback (most recent call last):
  33. File "C:\Users\Rayane_2\AppData\Local\r-miniconda\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
  34. main()
  35. File "C:\Users\Rayane_2\AppData\Local\r-miniconda\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
  36. json_out['return_val'] = hook(**hook_input['kwargs'])
  37. File "C:\Users\Rayane_2\AppData\Local\r-miniconda\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel
  38. return _build_backend().build_wheel(wheel_directory, config_settings,
  39. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\build_meta.py", line 416, in build_wheel
  40. return self._build_with_temp_dir(['bdist_wheel'], '.whl',
  41. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\build_meta.py", line 401, in _build_with_temp_dir
  42. self.run_setup()
  43. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
  44. exec(code, locals())
  45. File "<string>", line 218, in <module>
  46. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\__init__.py", line 107, in setup
  47. return distutils.core.setup(**attrs)
  48. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
  49. return run_commands(dist)
  50. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
  51. dist.run_commands()
  52. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
  53. self.run_command(cmd)
  54. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\dist.py", line 1234, in run_command
  55. super().run_command(command)
  56. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
  57. cmd_obj.run()
  58. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\wheel\bdist_wheel.py", line 346, in run
  59. self.run_command("build")
  60. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
  61. self.distribution.run_command(command)
  62. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\dist.py", line 1234, in run_command
  63. super().run_command(command)
  64. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
  65. cmd_obj.run()
  66. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run
  67. self.run_command(cmd_name)
  68. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
  69. self.distribution.run_command(command)
  70. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\dist.py", line 1234, in run_command
  71. super().run_command(command)
  72. File "C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-build-env-6m1cj1ox\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
  73. cmd_obj.run()
  74. File "<string>", line 130, in run
  75. File "<string>", line 167, in build_extension
  76. File "C:\Users\Rayane_2\AppData\Local\r-miniconda\lib\subprocess.py", line 369, in check_call
  77. raise CalledProcessError(retcode, cmd)
  78. subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Public\\Documents\\Wondershare\\CreatorTemp\\pip-install-s4im1wse\\dlib_6311ea7c12944928afe6fa5cda1f5d5d\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Public\\Documents\\Wondershare\\CreatorTemp\\pip-install-s4im1wse\\dlib_6311ea7c12944928afe6fa5cda1f5d5d\\build\\lib.win-amd64-cpython-310', '-DPYTHON_EXECUTABLE=C:\\Users\\Rayane_2\\AppData\\Local\\r-miniconda\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Public\\Documents\\Wondershare\\CreatorTemp\\pip-install-s4im1wse\\dlib_6311ea7c12944928afe6fa5cda1f5d5d\\build\\lib.win-amd64-cpython-310', '-A', 'x64']' returned non-zero exit status 1.
  79. [end of output]
  80. note: This error originates from a subprocess, and is likely not a problem with pip.
  81. ERROR: Failed building wheel for dlib
  82. ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects

I do not understand this error, cmake is already installed.

  1. import sys
  2. print(sys.version)
  3. 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)]

it seems error is coming from cmake installation , when trying cmake --version command in cmd , the command is not recognized by compiler .

  1. C:\Users\Rayane_2>cmake --version
  2. 'cmake' is not recognized as an internal or external command,
  3. operable program or batch file.

答案1

得分: 0

我解决了这个问题,以下是步骤:

  1. 检查你的Python、pip和CMake版本。 Dlib需要Python(2.7、3.5或更新版本)、pip(19.0或更新版本)和CMake(3.8或更新版本)。你可以用以下命令检查它们的版本:
  2. Python: python --versionpython3 --version
  3. pip: pip --versionpip3 --version
  4. CMake: cmake --version

我重新使用了官方网站 https://cmake.org/download/ 安装了cmake。

  1. 更新pip和setuptools。 旧版本可能与dlib不兼容。使用以下命令进行更新:

  2. pip install --upgrade pip

  3. pip install --upgrade setuptools

  4. 安装Visual Studio构建工具。 如果你使用的是Windows,你需要安装Visual Studio和C++构建工具。你可以从Visual Studio网站下载它们:https://visualstudio.microsoft.com/visual-cpp-build-tools/

  5. 前往Visual Studio下载页面 https://visualstudio.microsoft.com/downloads/

  6. 在“所有下载”部分,找到“Tools for Visual Studio 2019”。点击“查看所有下载”。

  7. 在打开的页面中,找到“Build Tools for Visual Studio 2019”,并点击旁边的“下载”按钮。

  8. 运行下载的安装程序。这将打开Visual Studio安装程序。

  9. 在安装程序中,在“工作负载”下,选择“C++构建工具”。

  10. 确保在右侧至少包括以下组件:
    - MSVC v142 - VS 2019 C++ x64/x86 构建工具
    - Windows 10 SDK
    - C++用于最新v142构建工具的CMake工具(x86和x64)
    - 用于x86和x64的最新v142构建工具的C++ ATL

  11. 点击“安装”开始安装。

  12. 安装完成后,可以再次在命令行或Jupyter cell中运行以下命令:pip install dlib

  13. 导入:import dlib

英文:

I solved the problem , those are the steps:

  1. Check your Python, pip, and CMake versions. Dlib requires Python (2.7, 3.5, or newer), pip (19.0 or newer), and CMake (3.8 or newer). You can check their versions with the following commands:
  2. Python: python --version or python3 --version
  3. pip: pip --version or pip3 --version
  4. CMake: cmake --version

I installed cmake again using official website https://cmake.org/download/

  1. Update pip and setuptools. Older versions might have compatibility issues with dlib. Use the following commands to update:

  2. pip install --upgrade pip

  3. pip install --upgrade setuptools

  4. Install Visual Studio build tools. If you're using Windows, you'll need Visual Studio and C++ build tools. You can download them from the Visual Studio website: https://visualstudio.microsoft.com/visual-cpp-build-tools/

  5. Go to the Visual Studio downloads page at https://visualstudio.microsoft.com/downloads/

  6. Under the "All downloads" section, find "Tools for Visual Studio 2019". Click on "See all downloads".

  7. In the opened page, find "Build Tools for Visual Studio 2019" and click the "Download" button next to it.

  8. Run the downloaded installer. This opens the Visual Studio Installer.

  9. In the installer, under "Workloads", select "C++ build tools".

  10. Make sure to include at least the following components on the right:
    - MSVC v142 - VS 2019 C++ x64/x86 build tools
    - Windows 10 SDK
    - C++ CMake tools for Windows
    - C++ ATL for latest v142 build tools (x86 & x64)

  11. Click "Install" to start the installation.

  12. Once done , install again from cmd / jupyter cell : pip install dlib

  13. Import using : import dlib

huangapple
  • 本文由 发表于 2023年7月23日 22:35:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76748794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定