在 Pycharm 上安装 dlib 时出错

在 Pycharm 上安装 dlib 时出错

我正在尝试安装dlib在 Pycharm(类似于 Anaconda)上,以便将其用于我的 Python 和 OpenCV 人脸检测项目。

我已经安装了 cMake 并升级了 Python,但仍然出现错误:

命令

pip install dlib

错误

FileNotFoundError: [WinError 2] The system cannot find the file specified

命令输出

Collecting dlib
  Using cached https://files.pythonhosted.org/packages/05/57/e8a8caa3c89a27f80bc78da39c423e2553f482a3705adc619176a3a24b36/dlib-19.17.0.tar.gz
Installing collected packages: dlib
Running setup.py install for dlib: started
Running setup.py install for dlib: finished with status 'error'
Complete output from command C:\Users\mehrs\PycharmProjects\project2\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\mehrs\\AppData\\Local\\Temp\\pycharm-packaging\\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\mehrs\AppData\Local\Temp\pip-record-_nvwlk_i\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\mehrs\PycharmProjects\project2\venv\include\site\python3.7\dlib:
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\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 120, in get_cmake_version
    out = subprocess.check_output(['cmake', '--version'])
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 472, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
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\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 261, in <module>
    'Topic :: Software Development',
  File "C:\Users\mehrs\PycharmProjects\project2\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\setuptools\__init__.py", line 129, in setup
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\mehrs\PycharmProjects\project2\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\setuptools\command\install.py", line 61, in run
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\install.py", line 545, in run
    self.run_command('build')
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 129, in run
    cmake_version = self.get_cmake_version()
  File "C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 125, in get_cmake_version
    "\n*******************************************************************\n")
RuntimeError:
*******************************************************************
 CMake must be installed to build the following extensions: dlib
*******************************************************************


----------------------------------------

Command "C:\Users\mehrs\PycharmProjects\project2\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\mehrs\\AppData\\Local\\Temp\\pycharm-packaging\\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\mehrs\AppData\Local\Temp\pip-record-_nvwlk_i\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\mehrs\PycharmProjects\project2\venv\include\site\python3.7\dlib" failed with error code 1 in C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

答案1

  1. 安装 Pycharm
  2. Windows 10
  3. Python 3.8.3(带有 pipenv,但也可以与 pip 一起使用)

例如:pipenv 安装(作为虚拟环境)

由于“pipenv install dlib”在尝试了一段时间后出现了安装错误,因此能够安装最新的 dlib 库(dlib==19.20.0)

下面是帮助我成功安装最新 dlib 的步骤 - 我们必须手动为 Python 编译 dlib

  1. 安装Visual Studio(我安装的是Microsoft Visual Studio Community 2019版本16.6.3)
  2. 确保选择 Visual C++ 或 C++ 环境 - 完成安装 - 不需要其他任何东西(在 Visual Studio 2019 中,转到单独组件选项卡、Cmake 的 Visual C++ 工具,然后选中“编译器、构建工具和运行时”部分下的复选框。)
  3. 去 -https://cmake.org/download/并下载 64 位的 cmake (我安装的是 cmake-3.18.0-rc4-win64-x64.msi)
  4. 安装时,请确保将 CMake 添加到系统路径(安装完成后 -> 检查环境变量是否存在)
  5. https://pypi.org/project/dlib/-> 点击“下载文件”
  6. dlib-19.20.0.tar.gz(我最新的版本)-> 下载相同的
  7. 提取文件“dlib-19.20.0.tar.gz”直到看到文件(dlib,dlib.egg-info,python_examples,tools,MANIFEST.in,PKG-INFO,README.md setup.cfg,setup.py)
  8. 复制所有这些文件(全选(ctrl+a)并复制(ctrl+c))-> 确保只复制这些文件,而不复制其父目录
  9. 转到 python 安装中的站点包(C:\Users<name>\AppData\Local\Programs\Python\Python38\Lib\site-packages)
  10. 粘贴步骤7、8中复制的所有文件
  11. 打开命令提示符并转到 -> C:\Users<name>\AppData\Local\Programs\Python\Python38\Lib\site-packages
  12. 执行命令 -> python setup.py install

这就是您应该完成的所有操作 - 完成该过程可能需要 5 - 10 分钟,最后您应该会看到类似下面的内容 已安装 c:\users<name>\appdata\local\programs\python\python38\lib\site-packages\dlib-19.20.0-py3.8-win-amd64.egg 正在处理 dlib==19.20.0 的依赖项 已完成处理 dlib==19.20.0 的依赖项

答案2

我收到此错误,您能告诉我原因吗?我已经为 CMAKE 安装了 Visual C++ 工具,但没有编译器、构建工具和运行时之类的东西

我发现错误是python是32位而编译器是64位,但是如何修复它

-- Configuring incomplete, errors occurred!
See also "C:/Users/Anil/AppData/Local/Programs/Python/Python38-32/Lib/site-packages/build/temp.win32-3.8/Release/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
  File "setup.py", line 223, in <module>
    setup(
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\setuptools\__init__.py", line 161, in setup
    return distutils.core.setup(**attrs)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\setuptools\command\install.py", line 67, in run
    self.do_egg_install()
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\setuptools\command\bdist_egg.py", line 173, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\setuptools\command\bdist_egg.py", line 159, in call_command
    self.run_command(cmdname)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\setuptools\command\install_lib.py", line 11, in run
    self.build()
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\install_lib.py", line 107, in build
    self.run_command('build_ext')
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "setup.py", line 135, in run
    self.build_extension(ext)
  File "setup.py", line 172, in build_extension
    subprocess.check_call(cmake_setup, cwd=build_folder)
  File "C:\Users\Anil\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Anil\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Anil\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\build\\lib.win32-3.8', '-DPYTHON_EXECUTABLE=C:\\Users\\Anil\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Anil\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\build\\lib.win32-3.8']' returned non-zero exit status 1.

相关内容