davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.57k stars 3.38k forks source link

ImportError: DLL load failed while importing _dlib_pybind11: Not Found。[Bug]: #2937

Closed DehaoMeng closed 5 months ago

DehaoMeng commented 7 months ago

What Operating System(s) are you seeing this problem on?

Windows

dlib version

19.24.99

Python version

3.12

Compiler

GCC 8.1 VS 2022

Expected Behavior

dlib.DLIB_USE_CUDA TRUE

Current Behavior

use import dlib in python error: ImportError: DLL load failed while importing _dlib_pybind11: not found。 in my env I can find this model Only python3.12 have this error! 3.11or 3.10 can use

Steps to Reproduce

conda create --name demo conda activate demo pip install build cmake boost python -m build --wheel pip install dist\dlib-19.24.99-cp312-cp312-win_amd64.whl python import dlib

Anything else?

no

DehaoMeng commented 7 months ago

archspec @ file:///croot/archspec_1697725767277/work blurhash==1.1.4 boltons @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/boltons_1699480450092/work boost==0.1 Brotli @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/brotli-split_1699473013692/work build==1.2.1 certifi @ file:///C:/b/abs_35d7n66oz9/croot/certifi_1707229248467/work/certifi cffi @ file:///C:/b/abs_924gv1kxzj/croot/cffi_1700254355075/work charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work cmake==3.29.0.1 colorama @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/colorama_1699472650914/work conda @ file:///C:/b/abs_89vd8hj61u/croot/conda_1708369170790/work conda-content-trust @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/conda-content-trust_1699553484152/work conda-libmamba-solver @ file:///croot/conda-libmamba-solver_1702997573971/work/src conda-package-handling @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/conda-package-handling_1699480603217/work conda_package_streaming @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/conda-package-streaming_1699475879769/work cryptography @ file:///C:/b/abs_e8cnomzw/croot/cryptography_1702071486468/work decorator==5.1.1 distro @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/distro_1701796812765/work dlib @ file:///D:/Desktop/dlib/dist/dlib-19.24.99-cp312-cp312-win_amd64.whl#sha256=50eb69973c14e4304d290d0371eb6d25fd64820169b3cf96297765e75431da2a greenlet==3.0.3 idna @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/idna_1699473483982/work jsonpatch @ file:///tmp/build/80754af9/jsonpatch_1615747632069/work jsonpointer==2.1 libmambapy @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/mamba-split_1701809371861/work/libmambapy Mastodon.py==1.8.1 menuinst @ file:///C:/b/abs_099kybla52/croot/menuinst_1706732987063/work numpy==1.26.4 opencv-python==4.9.0.80 packaging @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/packaging_1699472459356/work platformdirs @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/platformdirs_1701797392447/work pluggy @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/pluggy_1699472504117/work pybind11==2.12.0 pycosat @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/pycosat_1699482932804/work pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work pyproject_hooks==1.0.0 PySocks @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/pysocks_1699473336188/work python-dateutil==2.9.0.post0 python-magic-bin==0.4.14 requests @ file:///C:/b/abs_474vaa3x9e/croot/requests_1707355619957/work ruamel.yaml @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/ruamel.yaml_1699483184324/work setuptools==69.2.0 six==1.16.0 SQLAlchemy==2.0.29 tqdm @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/tqdm_1701808178601/work truststore @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/truststore_1701881385424/work typing_extensions==4.10.0 urllib3 @ file:///C:/b/abs_4etpfrkumr/croot/urllib3_1707770616184/work wheel==0.41.2 win-inet-pton @ file:///C:/Users/dev-admin/perseverance-python-buildout/croot/win_inet_pton_1699472992992/work zstandard==0.19.0 this is my package

davisking commented 7 months ago

Don't do any of that other stuff, just do pip install dlib. That should work without issue.

DehaoMeng commented 7 months ago

do pip install dlib .I can't use GPU to speed up computing

MrWhite928 commented 7 months ago

I have encountered a similar problem, but the difference is that my Python version is 3.8. Do you know how to solve it?

DehaoMeng commented 7 months ago

我遇到过类似的问题,但不同的是,我的Python版本是3.8。你知道怎么解决它吗?

Sorry, I have not used other versions for testing, and I only successfully compiled on one computer. After I changed the computer, this error still occurred when I used the above version. I think it may be caused by some execution error of my step.

dlib-issue-bot commented 6 months ago

Warning: this issue has been inactive for 35 days and will be automatically closed on 2024-05-27 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot commented 5 months ago

Warning: this issue has been inactive for 42 days and will be automatically closed on 2024-05-27 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot commented 5 months ago

Notice: this issue has been closed because it has been inactive for 45 days. You may reopen this issue if it has been closed in error.

StealUrKill commented 2 months ago

我遇到过类似的问题,但不同的是,我的Python版本是3.8。你知道怎么解决它吗?

Sorry, I have not used other versions for testing, and I only successfully compiled on one computer. After I changed the computer, this error still occurred when I used the above version. I think it may be caused by some execution error of my step.

Sorry for reopening this... I found the fix for this. At least on windows for me.

https://stackoverflow.com/questions/62255730/dlib-importerror-in-windows-10-on-line-dlib-pybind11-import-dll-load-failed

This can be solved by copying the cudnn64_7.dll (available here: https://developer.nvidia.com/cudnn) into the %CUDA_PATH%/bin directory (probably something like this: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin)

I am using the latest from below

Visual Studio 2022 Cmake TensorRT 10.4 GA for Windows 10, 11, Server 2019, Server 2022 and CUDA 12.0 to 12.6 ZIP Package cuDNN 9.4.0 CUDA Toolkit 12.6 Update 1

Install the CUDA toolkit first and reboot. After install the cuDNN. The path should have these already in it from the install C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\libnvvp C:\Program Files\NVIDIA\CUDNN\v9.4\bin\ C:\Program Files\NVIDIA\CUDNN\v9.4\

With system variables like these CUDA_PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6 CUDA_PATH_V12_6 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6

Now in the directory C:\Program Files\NVIDIA\CUDNN\v9.4

Move all the 12.6 files from C:\Program Files\NVIDIA\CUDNN\v9.4\bin\12.6 to C:\Program Files\NVIDIA\CUDNN\v9.4\bin Move all the 12.6 files from C:\Program Files\NVIDIA\CUDNN\v9.4\include\12.6 to C:\Program Files\NVIDIA\CUDNN\v9.4\inlcude Move all the 12.6 files from C:\Program Files\NVIDIA\CUDNN\v9.4\bin\12.6 to C:\Program Files\NVIDIA\CUDNN\v9.4\bin

If you're using tensorrt as well then you want to extract the zip and move all files and folders to C:\Program Files\NVIDIA\CUDNN\v9.4

Then you want to copy the file like the stackoverflow says (for me it was this)

This can be solved by copying the cudnn64_9.dll (from C:\Program Files\NVIDIA\CUDNN\v9.4\bin) into the %CUDA_PATH%/bin directory (probably something like this: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin)

Then

git clone https://github.com/davisking/dlib.git cd dlib mkdir build cd build cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 -DCMAKE_PREFIX_PATH="C:/Program Files/NVIDIA/CUDNN/v9.4"

You should see

-- Looking for cuDNN install...

-- Found cuDNN: C:/Program Files/NVIDIA/CUDNN/v9.4/lib/cudnn.lib -- Building a CUDA test project to see if your compiler is compatible with CUDA... CMake Warning (dev) at C:/Users/user/Downloads/dlib-master/dlib-master/dlib/cmake_utils/test_for_cuda/CMakeLists.txt:10 (find_package): Policy CMP0146 is not set: The FindCUDA module is removed. Run "cmake --help-policy CMP0146" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

This warning is for project developers. Use -Wno-dev to suppress it.

-- Building a cuDNN test project to check if you have the right version of cuDNN installed... CMake Warning (dev) at C:/Users/user/Downloads/dlib-master/dlib-master/dlib/cmake_utils/test_for_cudnn/CMakeLists.txt:7 (find_package): Policy CMP0146 is not set: The FindCUDA module is removed. Run "cmake --help-policy CMP0146" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

This warning is for project developers. Use -Wno-dev to suppress it.

-- Enabling CUDA support for dlib. DLIB WILL USE CUDA, compute capabilities: 50 -- Configuring done (12.2s) -- Generating done (0.1s) -- Build files have been written to: C:/Users/user/Downloads/dlib-master/dlib-master/dlib/build

Then cmake --build . --config Release and then you should see

-- Looking for cuDNN install... -- Found cuDNN: C:/Program Files/NVIDIA/CUDNN/v9.4/lib/cudnn.lib -- Enabling CUDA support for dlib. DLIB WILL USE CUDA, compute capabilities: 50 -- Configuring done (0.6s) -- Generating done (0.2s)

Run the following command from the source directory

python setup.py install

and then another output like

-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6 (found suitable version "12.6", minimum required is "7.5") -- Looking for cuDNN install... -- Found cuDNN: C:/Program Files/NVIDIA/CUDNN/v9.4/lib/cudnn.lib -- Building a CUDA test project to see if your compiler is compatible with CUDA... CMake Warning (dev) at C:/Users/user/Downloads/dlib-master/dlib-master/dlib/cmake_utils/test_for_cuda/CMakeLists.txt:10 (find_package): Policy CMP0146 is not set: The FindCUDA module is removed. Run "cmake --help-policy CMP0146" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

This warning is for project developers. Use -Wno-dev to suppress it.

-- Building a cuDNN test project to check if you have the right version of cuDNN installed... CMake Warning (dev) at C:/Users/user/Downloads/dlib-master/dlib-master/dlib/cmake_utils/test_for_cudnn/CMakeLists.txt:7 (find_package): Policy CMP0146 is not set: The FindCUDA module is removed. Run "cmake --help-policy CMP0146" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

This warning is for project developers. Use -Wno-dev to suppress it.

-- Enabling CUDA support for dlib. DLIB WILL USE CUDA, compute capabilities: 50 -- Configuring done (23.3s) -- Generating done (0.1s) -- Build files have been written to: C:/Users/user/Downloads/dlib-master/dlib-master/build/temp.win-amd64-cpython-311/Release Invoking CMake build: 'cmake --build . --config Release -- /m' MSBuild version 17.10.4+10fbfbf2e for .NET Framework

A successful build then ends with

Installed c:\users\user\appdata\local\programs\python\python311\lib\site-packages\dlib-19.24.99-py3.11-win-amd64.egg Processing dependencies for dlib==19.24.99 Finished processing dependencies for dlib==19.24.99

After all is said and done

Python 3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dlib
>>> print(dlib.DLIB_USE_CUDA)
True