Win10 和 Ubuntu 20.04 安裝 face_recognition 和 dlib

_jym 2022-01-07 15:03:27 阅读数:189

win10 win ubuntu face_recognition face

face_recognition是一個人臉識別庫。

WIN10安裝:

首先改一下下載源:

1.C:\Users\xx\pip,新建文件pip.ini
2.文件裏面輸入:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

然後安裝vs2019

需要勾選c++那一項。

安裝face_recognition步驟如下

命令行輸入:

1.python -m pip install --upgrade pip
2.pip install cmake
3.pip install dlib
4.pip install face_recognition

報錯原因及解决:

1.pip install 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++.

說明沒有安裝Visual Studio

安裝vs2019,勾選c++那一項進行安裝即可解决。

2 . pip install dlib出現ERROR: CMake must be installed to build dlib

先進行pip install cmake再pip install dlib

Ubuntu 20.04安裝

改下載源

mkdir ~/.pip // 創建隱藏的文件夾(注意用戶是root還是普通user)
vim ~/.pip/pip.conf // 創建一個pip.conf文件
// 在pip.conf中粘貼進下面內容(豆瓣源)
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
// wq保存一下就行了

然後終端輸入:

CC=gcc
CXX=g++
pip install face_recognition

報錯原因及解决:

Building wheels for collected packages: dlib
Building wheel for dlib (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9n08rmx4/dlib/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 /tmp/pip-wheel-ajvzzs1b
cwd: /tmp/pip-install-9n08rmx4/dlib/
Complete output (50 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.10 (default, Sep 28 2021, 16:10:42)
Invoking CMake setup: 'cmake /tmp/pip-install-9n08rmx4/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8 -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=Release'
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:49 (message):
Could not find compiler set in environment variable CC:
/usr/local/bin/gcc.
Call Stack (most recent call first):
CMakeLists.txt:14 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/tmp/pip-install-9n08rmx4/dlib/build/temp.linux-x86_64-3.8/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 222, in <module>
setup(
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.8/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3/dist-packages/wheel/bdist_wheel.py", line 223, in run
self.run_command('build')
File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.8/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 134, in run
self.build_extension(ext)
File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 171, in build_extension
subprocess.check_call(cmake_setup, cwd=build_folder)
File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-9n08rmx4/dlib/tools/python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8', '-DPYTHON_EXECUTABLE=/usr/bin/python3', '-DCMAKE_BUILD_TYPE=Release']' 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: face-recognition-models, dlib, face-recognition
Running setup.py install for dlib ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9n08rmx4/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 /tmp/pip-record-476x_oyc/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/jym/.local/include/python3.8/dlib
cwd: /tmp/pip-install-9n08rmx4/dlib/
Complete output (52 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
Building extension for Python 3.8.10 (default, Sep 28 2021, 16:10:42)
Invoking CMake setup: 'cmake /tmp/pip-install-9n08rmx4/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8 -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=Release'
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:49 (message):
Could not find compiler set in environment variable CC:
/usr/local/bin/gcc.
Call Stack (most recent call first):
CMakeLists.txt:14 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/tmp/pip-install-9n08rmx4/dlib/build/temp.linux-x86_64-3.8/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 222, in <module>
setup(
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.8/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3/dist-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/usr/lib/python3.8/distutils/command/install.py", line 589, in run
self.run_command('build')
File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.8/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 134, in run
self.build_extension(ext)
File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 171, in build_extension
subprocess.check_call(cmake_setup, cwd=build_folder)
File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-9n08rmx4/dlib/tools/python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8', '-DPYTHON_EXECUTABLE=/usr/bin/python3', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9n08rmx4/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 /tmp/pip-record-476x_oyc/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/jym/.local/include/python3.8/dlib Check the logs for full command output.

在終端輸入:

CC=gcc
CXX=g++

再進行pip install face_recognition就可以了

版权声明:本文为[_jym]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/01/202201071503271237.html