ModuleNotFoundError: Нет модуля с именем 'dlib' в pipenv - PullRequest
0 голосов
/ 31 января 2020

Извините, я новичок во всем этом. Я не могу установить dlib внутри виртуальной среды pipenv, однако могу установить и импортировать ее вне виртуальной среды 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.

Когда я попытался сделать то же самое за пределами виртуальной среды, все работало нормально.

Я из идей я очень ценю ваш совет.

Edit 1

Я попытался установить dlib в виртуальной среде pipenv с помощью conda, вот результат:

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 выше), но я все еще не могу установить dlib ни по pip3, ни по conda. И странно то, что ошибка conda говорит мне Your python: python=3.7, в то время как ошибка pip3 ясно говорит о том, что я использую python 3.5: Building extension for Python 3.5.9

Пожалуйста, советуйте.

1 Ответ

0 голосов
/ 05 февраля 2020

Попробуйте следующее:

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