在 Windows 10/11 上安装(python 库)face_recognition 的问题

Posted

技术标签:

【中文标题】在 Windows 10/11 上安装(python 库)face_recognition 的问题【英文标题】:problem in Installing (python Library) face_recognition on windows 10/11 【发布时间】:2021-12-28 06:42:57 【问题描述】:

我正在使用 python 3.9.9 点 21.3.1

我正在尝试安装 face_recognition

所以我安装了 CMake 然后当我尝试使用命令pip install dlib 安装 dlib 时,我得到了以下信息

Collecting dlib
  Using cached dlib-19.22.1.tar.gz (7.4 MB)
  Prep

    aring metadata (setup.py) ... done
    Building wheels for collected packag

es: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\aenas\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-78dld3fg\\dlib_098968d181654cc09e283aff4801a4b1\\setup.py'"'"'; __file__='"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-78dld3fg\\dlib_098968d181654cc09e283aff4801a4b1\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\aenas\AppData\Local\Temp\pip-wheel-hjnpx8xk'
       cwd: C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\
  Complete output (8 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

  ERROR: CMake must be installed to build 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: Command errored out with exit status 1:
     command: 'C:\Users\aenas\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-78dld3fg\\dlib_098968d181654cc09e283aff4801a4b1\\setup.py'"'"'; __file__='"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-78dld3fg\\dlib_098968d181654cc09e283aff4801a4b1\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\aenas\AppData\Local\Temp\pip-record-zbjc8ulw\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\aenas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Include\dlib'
         cwd: C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\
    Complete output (8 lines):
    running install
    running build
    running build_py
    package init file 'tools\python\dlib\__init__.py' not found (or not a regular file)
    running build_ext

    ERROR: CMake must be installed to build dlib

    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\aenas\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-78dld3fg\\dlib_098968d181654cc09e283aff4801a4b1\\setup.py'"'"'; __file__='"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-78dld3fg\\dlib_098968d181654cc09e283aff4801a4b1\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\aenas\AppData\Local\Temp\pip-record-zbjc8ulw\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\aenas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Include\dlib' Check the logs for full command output.**

当我尝试使用命令pip install face_recognition 安装 face_recognition 时 我得到了以下信息:

Collecting face_recognition
  Using cached face_recognition-1.3.0-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: face-recognition-models>=0.3.0 in c:\users\aenas\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from face_recognition) (0.3.0)
Collecting dlib>=19.7
  Using cached dlib-19.22.1.tar.gz (7.4 MB)
  Preparing metadata (setup.py) ... done
Collecting Click>=6.0
  Using cached click-8.0.3-py3-none-any.whl (97 kB)
Requirement already satisfied: numpy in c:\users\aenas\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from face_recognition) (1.21.4)
Requirement already satisfied: Pillow in c:\users\aenas\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from face_recognition) (8.4.0)
Requirement already satisfied: colorama in c:\users\aenas\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from Click>=6.0->face_recognition) (0.4.4)
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\aenas\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-cy9bzkon\\dlib_8e45a10b6067402ab676a29d5bd742c8\\setup.py'"'"'; __file__='"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-cy9bzkon\\dlib_8e45a10b6067402ab676a29d5bd742c8\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\aenas\AppData\Local\Temp\pip-wheel-elyfs9nv'
       cwd: C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\
  Complete output (8 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

  ERROR: CMake must be installed to build dlib

  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib, Click, face-recognition
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\aenas\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-cy9bzkon\\dlib_8e45a10b6067402ab676a29d5bd742c8\\setup.py'"'"'; __file__='"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-cy9bzkon\\dlib_8e45a10b6067402ab676a29d5bd742c8\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\aenas\AppData\Local\Temp\pip-record-oojov4ij\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\aenas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Include\dlib'
         cwd: C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\
    Complete output (8 lines):
    running install
    running build
    running build_py
    package init file 'tools\python\dlib\__init__.py' not found (or not a regular file)
    running build_ext

    ERROR: CMake must be installed to build dlib

    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\aenas\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-cy9bzkon\\dlib_8e45a10b6067402ab676a29d5bd742c8\\setup.py'"'"'; __file__='"'"'C:\\Users\\aenas\\AppData\\Local\\Temp\\pip-install-cy9bzkon\\dlib_8e45a10b6067402ab676a29d5bd742c8\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\aenas\AppData\Local\Temp\pip-record-oojov4ij\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\aenas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Include\dlib' Check the logs for full command output.

虽然我尝试了很多解决方案,但都没有解决我的问题

【问题讨论】:

"我安装了 CMake..." 是否在 %PATH% 中可用?你能在终端里运行cmake吗? 不,我不能,但是当我输入命令 pip install cmake 时,我得到以下信息:Requirement already satisfied: cmake in c:\users\aenas\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (3.21.4) cmake所在的目录添加到%PATH% 你能告诉我怎么做吗? ***.com/search?q=add+directory+to+PATH 【参考方案1】:

幸运的是,我解决了这个问题。以下是下载 face_recognition 库的步骤:

1- 安装python:

在命令提示符下输入python并点击回车,这将打开 微软商店为你,“点击下载”或“安装”下载并 安装蟒蛇。 "检查是否已下载,在 命令提示符

2- 如果没有 pip,请安装:

转到:https://pypi.org/project/pip-download/ 点击下载文件。现在打开下载的文件,然后单击右键 用鼠标选择“在 Windows 终端中打开”。现在输入命令 python get-pip.py。现在应该安装您的 pip,在 终端检查是否安装

3-为 C++ 安装 Visual Studio 工具

前往:https://visualstudio.microsoft.com/ 并下载社区 VS的版本。下载后安装并选择以下 安装页面中的选项:image1image2

然后选择安装

4- 安装cmake

输入命令pip install cmake并等待安装。

5- 将 cmake 添加到 Path 变量中

按照以下链接中的说明了解如何添加 你的路径变量的东西: https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/

6- 安装 dlib

在命令提示符下写入如下命令:pip install dlib

7- 安装人脸识别

在命令提示符下写入以下命令:pip install face_recognition

8- 在 PyCharm 中启动您的项目

单击文件单击搜索类型“解释器”中的Sittings选择 “python解释器”选择“显示全部”点击“+”号选择 系统解释器选择其路径开始的解释器 “用户”目录

这是我用来解决问题的解决方案

【讨论】:

此解决方案适用于 Windows。我在 Mac M1 中导入 face_recognition 时遇到了同样的问题。你知道任何解决方案吗? @HaiderAbbas 很遗憾没有,对此感到抱歉。希望你能尽快解决。

以上是关于在 Windows 10/11 上安装(python 库)face_recognition 的问题的主要内容,如果未能解决你的问题,请参考以下文章

怎么在32位windows系统上搭建爬虫框架scrapy?

已安装pytho3.4却提示没有添加注册表Pythonversion3.4required,whichwasnotfoundintheregistry

在 windows 10 pro 上设置 python

caffe pytho接口

记一次阿里云服务器安装Python的血泪史

python在windows和linux下的安装和配置