解决ModuleNotFoundError: No module named ‘dlib‘

代码

import dlib

报错

ModuleNotFoundError: No module named 'dlib'

操作

pip install dlib

报错

DEPRECATION: Could not build wheels for dlib which do not use PEP 517. pip will fall back to legacy 'setup.py install' for these. pip 21.0 will remove support for this functionality. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
Installing collected packages: dlib
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\AINUC\python-v\TESTCV\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\AINUC\\AppData\\Local\\Temp\\pip-install-gtxywsnk\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\AINUC\\AppData\\Local\\Temp\\pip-install-gtxywsnk\\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\AINUC\AppData\Local\Temp\pip-record-yrcn1l_i\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\AINUC\python-v\TESTCV\include\site\python3.6\dlib'
         cwd: C:\Users\AINUC\AppData\Local\Temp\pip-install-gtxywsnk\dlib\
    Complete output (55 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
    Traceback (most recent call last):
      File "C:\Users\AINUC\AppData\Local\Temp\pip-install-gtxywsnk\dlib\setup.py", line 120, in get_cmake_version
        out = subprocess.check_output(['cmake', '--version'])
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\subprocess.py", line 336, in check_output
        **kwargs).stdout
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\subprocess.py", line 403, in run
        with Popen(*popenargs, **kwargs) as process:
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\subprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\subprocess.py", line 997, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] 系统找不到指定的文件。

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "", line 1, in 
      File "C:\Users\AINUC\AppData\Local\Temp\pip-install-gtxywsnk\dlib\setup.py", line 262, in 
        'Topic :: Software Development',
      File "C:\Users\AINUC\python-v\TESTCV\lib\site-packages\setuptools\__init__.py", line 163, in setup
        return distutils.core.setup(**attrs)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "C:\Users\AINUC\python-v\TESTCV\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\ainuc\appdata\local\programs\python\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "C:\Users\AINUC\AppData\Local\Temp\pip-install-gtxywsnk\dlib\setup.py", line 129, in run
        cmake_version = self.get_cmake_version()
      File "C:\Users\AINUC\AppData\Local\Temp\pip-install-gtxywsnk\dlib\setup.py", line 125, in get_cmake_version
        "\n*******************************************************************\n")
    RuntimeError:
    *******************************************************************
     CMake must be installed to build the following extensions: _dlib_pybind11
    *******************************************************************

    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\AINUC\python-v\TESTCV\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\AINUC\\AppData\\Local\\Temp\\pip-install-gtxywsnk\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\AINUC\\AppData\\Local\\Temp\\pip-install-gtxywsnk\\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\AINUC\AppData\Local\Temp\pip-record-yrcn1l_i\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\AINUC\python-v\TESTCV\include\site\python3.6\dlib' Check the logs for full command output.

解决方法

pip install dlib==19.6.1

指定版本就好了

1.若还是无法解决,那就安装

pip install cmake

Visual Studio 2017

链接:https://pan.baidu.com/s/1w7uV9ZTI5MahfQ0zo78fMw  密码:avp0

2.若还是无法解决,那就安装

Visual Studio 2017

链接:https://pan.baidu.com/s/1w7uV9ZTI5MahfQ0zo78fMw  密码:avp0

欢迎大家交流学习,任何问题都可以留言

你可能感兴趣的:(日常报错,python)