无法在 python 3.7.6 上安装 DLIB

Unable to install DLIB on python 3.7.6

我正在使用 python 3.7.6 创建人脸识别系统。 为此,依赖项是:

  1. opencv-python

  2. cmake

  3. dlib

我已经成功安装opencv-python,cmake

但是在安装 Python 3.7.6 的 dlib 库时。我收到一个错误:

Collecting
https: // files.pythonhosted.org / packages / 1
e / 62 / aacb236d21fbd08148b1d517d58a9d80ea31bdcd386d26f21f8b23b1eb28 / dlib - 19.18
.0.tar.gz
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...error
    ERROR: Command
    errored
    out
    with exit status 1:
        command: 'C:\Users\hp\PycharmProjects\Face-Attendance\venv\Scripts\python.exe' - u - c
    'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\hp
\AppData\Local\Temp\pip - req - build - s30f1uyb\setup.py
'"'"'; __file__='"'"'
C:\Users\hp\AppData\Local\Temp\pip - req - build - s30f1uyb\setup.py
'"'"';f = getattr(t
okenize, '"'"'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\hp\AppData\Local\Temp\pip - record - gf1sikyf\install - record.
    txt
' --single-version-externally-managed --compile --install-headers '
C:\Users\hp\PycharmProjects\Face - Attendance\venv\include\site\python3
.7\dlib
'
cwd: C:\Users\hp\AppData\Local\Temp\pip - req - build - s30f1uyb \
    Complete
output(57
lines):
running
install
running
build
running
build_py
package
init
file
'dlib\__init__.py'
not found( or not a
regular
file)
running
build_ext
Building
extension
for Python 3.7.6 (tags / v3.7.6:43364
a7ae0, Dec
19
2019, 00: 42:30) [MSC v.1916 64 bit(AMD64)]
Invoking
CMake
setup: 'cmake C:\Users\hp\AppData\Local\Temp\pip-req-build-s30f1uyb\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\hp\AppData\Local\Temp\p
ip - req - build - s30f1uyb\build\lib.win - amd64 - 3.7 - DPYTHON_EXECUTABLE = C:\Users\hp\PycharmProjects\Face - Attendance\venv\Scripts\python.exe - DCMAKE_LIBRARY_OUTPUT_DIRECTOR
Y_RELEASE = C:\Users\hp\AppData\Local\Temp\pip - req - build - s30f1uyb\build\lib.win - amd64 - 3.7 - A
x64
'
- - Building
for: NMake
Makefiles
CMake
Error
at
CMakeLists.txt: 3(project):
Generator

NMake
Makefiles

does
not support
platform
specification, but
platform

x64

was
specified.

    CMake
Error: CMAKE_C_COMPILER
not set, after
EnableLanguage
CMake
Error: CMAKE_CXX_COMPILER
not set, after
EnableLanguage
- - Configuring
incomplete, errors
occurred!
See
also
"C:/Users/hp/AppData/Local/Temp/pip-req-build-s30f1uyb/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
    Traceback(most
recent
call
last):
File
"<string>", line
1, in < module >
        File
"C:\Users\hp\AppData\Local\Temp\pip-req-build-s30f1uyb\setup.py", line
261, in < module >
          'Topic :: Software Development',
          File
"C:\Users\hp\PycharmProjects\Face-Attendance\venv\lib\site-packages\setuptools\__init__.py", line
153, in setup
return distutils.core.setup(**attrs)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\core.py", line
148, in setup
dist.run_commands()
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line
966, in run_commands
self.run_command(cmd)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line
985, in run_command
cmd_obj.run()
File
"C:\Users\hp\PycharmProjects\Face-Attendance\venv\lib\site-packages\setuptools\command\install.py", line
61, in run
return orig.install.run(self)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\command\install.py", line
545, in run
self.run_command('build')
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\cmd.py", line
313, in run_command
self.distribution.run_command(command)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line
985, in run_command
cmd_obj.run()
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\command\build.py", line
135, in run
self.run_command(cmd_name)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\cmd.py", line
313, in run_command
self.distribution.run_command(command)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line
985, in run_command
cmd_obj.run()
File
"C:\Users\hp\AppData\Local\Temp\pip-req-build-s30f1uyb\setup.py", line
135, in run
self.build_extension(ext)
File
"C:\Users\hp\AppData\Local\Temp\pip-req-build-s30f1uyb\setup.py", line
172, in build_extension
subprocess.check_call(cmake_setup, cwd=build_folder)
File
"C:\Users\hp\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line
363, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command
'['
cmake
', '
C:\Users\hp\AppData\Local\Temp\pip - req - build - s30f1uyb\tools\python
', ' - DCMAKE_LIBRARY_OUTPUT_DIRECTORY
=C:\Users\hp\AppData\Local\Temp\pip - req - build - s30f1uyb\build\lib.win - amd64 - 3.7
', ' - DPYTHON_EXECUTABLE = C:\Users\hp\PycharmProjects\Face - Attendance\venv\ \
    Scripts\python.exe
', ' - DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE = C:\Users\hp\AppData\Local\Temp\pip - req - build - s30f1uyb\build\lib.win - amd64 - 3.7
', ' - A
', '
x64
']'
returned
non - zero
exit
status
1.
----------------------------------------
ERROR: Command
errored
out
with exit status 1: 'C:\Users\hp\PycharmProjects\Face-Attendance\venv\Scripts\python.exe' - u - c
'import io, os, sys, setuptools, tokenize;
sys.argv[0] = '"'"'C:\Users\hp\AppData\Local\Temp\pip-req-build-s30f1uyb\setup.py'"'"';
__file__ = '"'"'C:\Users\hp\AppData\Local\Temp\pip-req-build-s30f
1u
yb\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\hp\AppData\Local\Temp\pi
p - record - gf1sikyf\install - record.txt
' --single-version-externally-managed --compile --install-headers '
C:\Users\hp\PycharmProjects\Face - Attendance\venv\include\site \
    python3
.7\dlib
' Check the logs for full command output.

但我已经有一个名为 MinGW 的 C++ 编译器,也可以通过终端中的 gcc 访问它。

但是如何让 DLIB 使用我的 MinGW 编译器而不是 Visual Studio?

dlib 19.22 在 MSYS2 shell.

下与 MinGW-w64 构建得很好

我用cmake to configure and ninja搭建。

除了 -G"MSYS Makefiles" 之外不需要特殊的 cmake 参数来使用 MSYS 的 make。或者您可以使用 -GNinja 来指定 ninja 作为构建工具,这样会快很多。

对于发布版本,您还可以添加 -DCMAKE_BUILD_TYPE:STRING=Release

最后,您可以为静态构建设置 -DBUILD_SHARED_LIBS:BOOL=OFF 或为共享构建设置 -DBUILD_SHARED_LIBS:BOOL=ON

简而言之,要使用 MSYS 构建共享 dlib,您可以这样做(将 /path/where/to/install 更改为所需的安装位置):

cmake.exe -G"MSYS Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=/path/where/to/install -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -S. -Bbuild_shared
make -Cbuild_shared install/strip

Dlib 需要核心 C++ 依赖项才能编译。我建议你使用 deepface。它更轻巧。

#!pip install deepface
from deepface import DeepFace
obj = DeepFace.verify("img1.jpg", "img2.jpg")