繁体   English   中英

ModuleNotFoundError:pipenv 中没有名为“dlib”的模块

[英]ModuleNotFoundError: No module named 'dlib' in pipenv

对不起,我对这一切都很陌生。 我无法在 pipenv 虚拟环境中安装dlib ,但是,我可以在 pipenv 虚拟环境之外安装和导入它。

当我导航到包含我的代码的文件夹并输入pipenv shell然后输入python3 example.py这是我要运行的代码时,我收到此错误:

import dlib
ModuleNotFoundError: No module named 'dlib'

然后我尝试使用以下命令安装 dlib:

$ sudo apt-get update
$ sudo apt-get install build-essential cmake
$ sudo apt-get install libopenblas-dev liblapack-dev 
$ sudo apt-get install libx11-dev libgtk-3-dev
$ sudo apt-get install python python-dev python-pip
$ sudo apt-get install python3 python3-dev python3-pip
$ pip3 install dlib

除了最后一个命令外,一切正常,这是我得到的输出,红色:

$ pip3 install dlib
Collecting dlib
  Using cached dlib-19.19.0.tar.gz (3.2 MB)
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/hany/.local/share/virtualenvs/vesselware-rtITNVcC/bin/python3.5m -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-24bjeekz/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-24bjeekz/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-3n4hx6v_
       cwd: /tmp/pip-install-24bjeekz/dlib/
  Complete output (292 lines):
  running bdist_wheel
  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
  Building extension for Python 3.5.9 (default, Nov 24 2019, 01:35:13)
  Invoking CMake setup: 'cmake /tmp/pip-install-24bjeekz/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-24bjeekz/dlib/build/lib.linux-x86_64-3.5 -DPYTHON_EXECUTABLE=/home/hany/.local/share/virtualenvs/vesselware-rtITNVcC/bin/python3.5m -DCMAKE_BUILD_TYPE=Release'

/tmp/pip-install-24bjeekz/dlib/dlib/external/pybind11/include/pybind11/detail/common.h:111:10: fatal error: Python.h: No such file or directory
     #include <Python.h>
              ^~~~~~~~~~
    compilation terminated.
    CMakeFiles/dlib_python.dir/build.make:134: recipe for target 'CMakeFiles/dlib_python.dir/src/svm_c_trainer.cpp.o' failed
    make[2]: *** [CMakeFiles/dlib_python.dir/src/svm_c_trainer.cpp.o] Error 1
    CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/dlib_python.dir/all' failed
    make[1]: *** [CMakeFiles/dlib_python.dir/all] Error 2
    Makefile:83: recipe for target 'all' failed
    make: *** [all] Error 2
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-24bjeekz/dlib/setup.py", line 261, in <module>
        'Topic :: Software Development',
      File "/home/hany/.local/share/virtualenvs/vesselware-rtITNVcC/lib/python3.5/site-packages/setuptools/__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.5/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/home/hany/.local/share/virtualenvs/vesselware-rtITNVcC/lib/python3.5/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/lib/python3.5/distutils/command/install.py", line 583, in run
        self.run_command('build')
      File "/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/usr/lib/python3.5/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-24bjeekz/dlib/setup.py", line 135, in run
        self.build_extension(ext)
      File "/tmp/pip-install-24bjeekz/dlib/setup.py", line 175, in build_extension
        subprocess.check_call(cmake_build, cwd=build_folder)
      File "/usr/lib/python3.5/subprocess.py", line 271, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '-j4']' returned non-zero exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/hany/.local/share/virtualenvs/vesselware-rtITNVcC/bin/python3.5m -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-24bjeekz/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-24bjeekz/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-ifngrgm8/install-record.txt --single-version-externally-managed --compile --install-headers /home/hany/.local/share/virtualenvs/vesselware-rtITNVcC/include/site/python3.5/dlib Check the logs for full command output.

当我尝试在虚拟环境之外做同样的事情时,一切正常。

我没有想法,我非常感谢你的建议。

编辑 1

我尝试使用 conda 在 pipenv 虚拟环境中安装 dlib,结果如下:

Launching subshell in virtual environment…
 . /home/hano/.local/share/virtualenvs/vesselware-rtITNVcC/bin/activate
hano@hano-asus:~/scripts/vesselware$  . /home/hano/.local/share/virtualenvs/vesselware-rtITNVcC/bin/activate
(vesselware) hano@hano-asus:~/scripts/vesselware$ conda install -c menpo dlib
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: | 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                                                                                  

UnsatisfiableError: The following specifications were found                                                                                                             
to be incompatible with the existing python installation in your environment:

Specifications:

  - dlib -> python[version='2.7.*|3.5.*|>=3.5,<3.6.0a0']
  - dlib -> python[version='>=2.7,<2.8.0a0']

Your python: python=3.7

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with each other:



Package certifi conflicts for:
python=3.7 -> pip -> setuptools -> certifi[version='>=2016.09|>=2016.9.26']
dlib -> python=3.5 -> pip -> setuptools -> certifi[version='>=2016.09|>=2016.9.26']
Package wheel conflicts for:
dlib -> python=3.5 -> pip -> wheel
python=3.7 -> pip -> wheel
Package pip conflicts for:
dlib -> python=3.5 -> pip
python=3.7 -> pip
Package ca-certificates conflicts for:
python=3.7 -> openssl[version='>=1.1.1a,<1.1.2a'] -> ca-certificates
dlib -> python=3.5 -> ca-certificates
Package setuptools conflicts for:
python=3.7 -> pip -> setuptools
dlib -> python=3.5 -> pip -> setuptools

编辑 2

我确保 pipenv 使用 python 3.5(如您在上面的 pip3 错误中所见),但我仍然无法通过 pip3 或 conda 安装 dlib。 奇怪的是 conda 错误告诉我Your python: python=3.7而 pip3 错误明确指出我正在使用 python 3.5: Building extension for Python 3.5.9

请指教。

请尝试以下操作:

conda create --name python3_5 python=3.5
conda activate python3_5
conda install -c menpo dlib

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM