dlib icon indicating copy to clipboard operation
dlib copied to clipboard

DLL load failed for CUDA on Python 3.8 for Windows

Open cashlo opened this issue 5 years ago • 27 comments

Expected Behavior

>>> import dlib
>>> :)

Current Behavior

>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing dlib: The specified module could not be found.
>>> :(

Steps to Reproduce

  1. Install CUDA
  2. Install cuDNN
  3. git clone https://github.com/davisking/dlib.git
  4. python setup.py install
  5. python -c"import dlib"

Because of A change in Python 3.8 for Windows, Python no longer searches for DLLs in directories listed in the PATH environment variable and fails to find curand64_10.dll, this is fixed after running os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin'))

  • Version: 19.19.99
  • Where did you get dlib: this github repo
  • Platform: Python 3.8 64-bit for Windows 10

cashlo avatar Mar 28 '20 04:03 cashlo

Urg, windows dynamic loading is such a mess :(

davisking avatar Mar 28 '20 11:03 davisking

I'm marking this help wanted because I'm not feeling super motivated to figure out how to fix this right now. So if someone wants to make this work I would much appreciate it.

It seems like the solution is to make CMake/setup.py generate a init.py that includes the appropriate os.add_dll_directory() call and then imports everything from the compiled dlib library users currently import.

davisking avatar Mar 28 '20 18:03 davisking

Let me see if I can do that in the next few days, I have everything needed to reproduce it anyway.

cashlo avatar Mar 28 '20 22:03 cashlo

Expected Behavior

>>> import dlib
>>> :)

Current Behavior

>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing dlib: The specified module could not be found.
>>> :(

Steps to Reproduce

  1. Install CUDA
  2. Install cuDNN
  3. git clone https://github.com/davisking/dlib.git
  4. python setup.py install
  5. python -c"import dlib"

Because of A change in Python 3.8 for Windows, Python no longer searches for DLLs in directories listed in the PATH environment variable and fails to find curand64_10.dll, this is fixed after running os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin'))

  • Version: 19.19.99
  • Where did you get dlib: this github repo
  • Platform: Python 3.8 64-bit for Windows 10

I followed the same steps but I'm still getting the error of DLL load failed while importing dlib: The specified module could not be found

Mouradost avatar May 13 '20 22:05 Mouradost

Well, clearly I failed to work on this. This seems to be a much bigger change than I expected. @Mouradost do you have the dlls in your CUDA_PATH?

cashlo avatar May 28 '20 07:05 cashlo

@cashlo Yes I do since I'm using Tensorflow with the GPU here is my CUDA_PATHs

image

Mouradost avatar May 30 '20 03:05 Mouradost

For some reason:

Test1: 1 - Open a terminal 2 - Run the python command 3 - Impor dlib

Result: Causes DLL error

Test2: 1 - Open Terminal 2 - Run the python command 3 - import cv2 4 - import dlib

Result: No error, also, i checked the version! 💯

image

issaiass avatar Jun 07 '20 17:06 issaiass

I just pushed a change to how dlib is packaged that should fix this. So pull the latest dlib from github and try installing that version.

davisking avatar Jun 07 '20 21:06 davisking

For some reason:

Test1: 1 - Open a terminal 2 - Run the python command 3 - Impor dlib

Result: Causes DLL error

Test2: 1 - Open Terminal 2 - Run the python command 3 - import cv2 4 - import dlib

Result: No error, also, i checked the version! 💯

image

I just pushed a change to how dlib is packaged that should fix this. So pull the latest dlib from github and try installing that version.

still getting DLL errors image

Mouradost avatar Jun 08 '20 07:06 Mouradost

What's in your CUDA_PATH environment variable?

davisking avatar Jun 09 '20 11:06 davisking

What's in your CUDA_PATH environment variable?

image

Mouradost avatar Jun 10 '20 07:06 Mouradost

@Mouradost That doesn't look like the contents of the CUDA_PATH variable, but PATH or something else. I say this because it would be very surprising if all those c:\windows paths were in CUDA_PATH.

davisking avatar Jun 10 '20 11:06 davisking

@Mouradost That doesn't look like the contents of the CUDA_PATH variable, but PATH or something else. I say this because it would be very surprising if all those c:\windows paths were in CUDA_PATH.

image my bad sorry

Mouradost avatar Jun 10 '20 13:06 Mouradost

So whats in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin?

davisking avatar Jun 11 '20 11:06 davisking

So whats in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin?

These are the files in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin image

Mouradost avatar Jun 14 '20 08:06 Mouradost

I don't see cudnn's .dll file in that list. You need to install cudnn. Which is curious, since cmake must have found a copy of cudnn somewhere on your computer based on other things you said.

On Sun, Jun 14, 2020 at 4:08 AM mourad lablack [email protected] wrote:

So whats in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin? These are the files in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin [image: image] https://user-images.githubusercontent.com/17816194/84588343-2be56e00-ae59-11ea-9146-d744a4594f25.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/davisking/dlib/issues/2039#issuecomment-643733806, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPYFRZH72KFTJVMOR5QMLTRWSAQXANCNFSM4LVOATAQ .

davisking avatar Jun 16 '20 18:06 davisking

I don't see cudnn's .dll file in that list. You need to install cudnn. Which is curious, since cmake must have found a copy of cudnn somewhere on your computer based on other things you said. On Sun, Jun 14, 2020 at 4:08 AM mourad lablack @.***> wrote: So whats in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin? These are the files in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin [image: image] https://user-images.githubusercontent.com/17816194/84588343-2be56e00-ae59-11ea-9146-d744a4594f25.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2039 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPYFRZH72KFTJVMOR5QMLTRWSAQXANCNFSM4LVOATAQ .

I have it under a different folder on c:\tools\cuda\bin should I add a copy to the C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin ?

Mouradost avatar Jun 17 '20 07:06 Mouradost

it's working awesome thank you @davisking I wonder could you guys give away a possibility to specify the path for cudnn if it's not moved to the cuda main folder? or directly grab it from the windows paths? like tensorflow do

Mouradost avatar Jun 17 '20 07:06 Mouradost

Where was it? Oh you noted in your other comment. Really we should make the install process record the location of the copy it found rather than expecting the user to do something special.

davisking avatar Jun 17 '20 10:06 davisking

@Mouradost I just pushed a change to github that should make this work without needing to assume anything about CUDA_PATH. So try the latest dlib on github.

davisking avatar Jun 18 '20 01:06 davisking

@Mouradost I just pushed a change to github that should make this work without needing to assume anything about CUDA_PATH. So try the latest dlib on github.

Sure I will give you my feedback thank you for your consideration and your help

Mouradost avatar Jun 18 '20 08:06 Mouradost

Where was it? Oh you noted in your other comment. Really we should make the install process record the location of the copy it found rather than expecting the user to do something special.

I had the habit to create a separate folder in the C:\ called tools and I put my cudnn files there which make it easy to find and change only the cudnn files if I want to use different version on cudnn without touching cuda that's why I thought it will be better to have your library allowing for additional paths.

Mouradost avatar Jun 18 '20 08:06 Mouradost

Expected Behavior

>>> import dlib
>>> :)

Current Behavior

>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing dlib: The specified module could not be found.
>>> :(

Steps to Reproduce

1. Install CUDA

2. Install cuDNN

3. `git clone https://github.com/davisking/dlib.git`

4. `python setup.py install`

5. `python -c"import dlib"`

Because of A change in Python 3.8 for Windows, Python no longer searches for DLLs in directories listed in the PATH environment variable and fails to find curand64_10.dll, this is fixed after running os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin'))

* **Version**: 19.19.99

* **Where did you get dlib**: this github repo

* **Platform**: Python 3.8 64-bit for Windows 10

I had a situation that dlib crashed when I did import it, in general I did the following. I changed setup.py and set it to compile Debug, but with Release it didn't work on Win 7 x 4 Py 3.7.

link on setup_for Debug compile https://drive.google.com/file/d/1Wfy9ou3yYce4wqywY22jPxC9IkN6_Dch

ElPrg avatar Sep 21 '20 18:09 ElPrg

I instal version Dlib 19.7.0. on python 3,6.13

pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f all works... but may be any advices about new versions?

VasylKolomiiets avatar Apr 03 '21 08:04 VasylKolomiiets

I work in:

Windows10 CUDA10.1 Anaconda Python 3.8

Steps to reproduce

  1. Install CUDA
  2. Install cuDNN
  3. Install Anaconda
  4. create env
  5. in terminal write conda install dlib -c conda-forge Environment (conda list):
> (dlib) C:\Users\Vasil>conda list
> # packages in environment at D:\Games\conda\envs\dlib:
> #
> # Name                    Version                   Build  Channel
> ca-certificates           2020.12.5            h5b45459_0    conda-forge
> certifi                   2020.12.5        py38haa244fe_1    conda-forge
> dlib                      19.21.1          py38h082dfc2_0    conda-forge
> intel-openmp              2020.3             h57928b3_311    conda-forge
> jpeg                      9d                   h8ffe710_0    conda-forge
> libblas                   3.9.0                     8_mkl    conda-forge
> libcblas                  3.9.0                     8_mkl    conda-forge
> liblapack                 3.9.0                     8_mkl    conda-forge
> libpng                    1.6.37               h1d00b33_2    conda-forge
> mkl                       2020.4             hb70f87d_311    conda-forge
> numpy                     1.20.1           py38h0cc643e_0    conda-forge
> openssl                   1.1.1k               h8ffe710_0    conda-forge
> pip                       21.0.1             pyhd8ed1ab_0    conda-forge
> python                    3.8.8           h7840368_0_cpython    conda-forge
> python_abi                3.8                      1_cp38    conda-forge
> setuptools                49.6.0           py38haa244fe_3    conda-forge
> sqlite                    3.35.3               h8ffe710_0    conda-forge
> vc                        14.2                 hb210afc_4    conda-forge
> vs2015_runtime            14.28.29325          h5e1d092_4    conda-forge
> wheel                     0.36.2             pyhd3deb0d_0    conda-forge
> wincertstore              0.2             py38haa244fe_1006    conda-forge
> zlib                      1.2.11            h62dcd97_1010    conda-forge
> 
> (dlib) C:\Users\Vasil>

Details about conda and system ( conda info ):

>     active environment : dlib
>     active env location : D:\Games\conda\envs\dlib
>             shell level : 1
>        user config file : C:\Users\Vasil\.condarc
>  populated config files : C:\Users\Vasil\.condarc
>           conda version : 4.9.2
>     conda-build version : 3.20.5
>          python version : 3.8.5.final.0
>        virtual packages : __cuda=11.2=0
>                           __win=0=0
>                           __archspec=1=x86_64
>        base environment : D:\Games\conda  (writable)
>            channel URLs : https://conda.anaconda.org/conda-forge/win-64
>                           https://conda.anaconda.org/conda-forge/noarch
>                           https://repo.anaconda.com/pkgs/main/win-64
>                           https://repo.anaconda.com/pkgs/main/noarch
>                           https://repo.anaconda.com/pkgs/r/win-64
>                           https://repo.anaconda.com/pkgs/r/noarch
>                           https://repo.anaconda.com/pkgs/msys2/win-64
>                           https://repo.anaconda.com/pkgs/msys2/noarch
>           package cache : D:\Games\conda\pkgs
>                           C:\Users\Vasil\.conda\pkgs
>                           C:\Users\Vasil\AppData\Local\conda\conda\pkgs
>        envs directories : D:\Games\conda\envs
>                           C:\Users\Vasil\.conda\envs
>                           C:\Users\Vasil\AppData\Local\conda\conda\envs
>                platform : win-64
>              user-agent : conda/4.9.2 requests/2.24.0 CPython/3.8.5 Windows/10 Windows/10.0.19041
>           administrator : False
>              netrc file : None
>            offline mode : False

What seams strange - that line virtual packages : __cuda=11.2=0 when I have CUDA10.1

All I did - just install dlib in new env and try to do import:

(dlib) C:\Users\Vasil>conda install dlib
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: D:\Games\conda\envs\dlib

  added / updated specs:
    - dlib


The following NEW packages will be INSTALLED:

  dlib               conda-forge/win-64::dlib-19.21.1-py38h082dfc2_0
  intel-openmp       conda-forge/win-64::intel-openmp-2020.3-h57928b3_311
  jpeg               conda-forge/win-64::jpeg-9d-h8ffe710_0
  libblas            conda-forge/win-64::libblas-3.9.0-8_mkl
  libcblas           conda-forge/win-64::libcblas-3.9.0-8_mkl
  liblapack          conda-forge/win-64::liblapack-3.9.0-8_mkl
  libpng             conda-forge/win-64::libpng-1.6.37-h1d00b33_2
  mkl                conda-forge/win-64::mkl-2020.4-hb70f87d_311
  numpy              conda-forge/win-64::numpy-1.20.1-py38h0cc643e_0
  zlib               conda-forge/win-64::zlib-1.2.11-h62dcd97_1010


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

(dlib) C:\Users\Vasil>python
Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 15:50:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  
  File "D:\Games\conda\envs\dlib\lib\site-packages\dlib\__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed while importing _dlib_pybind11: A dynamic link library (DLL) initialization routine failed.

here is my windows PATH

CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1 CUDA_PATH_V10_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1 ...      
PATH=D:\Games\conda\envs\dlib;D:\Games\conda\envs\dlib\Library\mingw-w64\bin;
D:\Games\conda\envs\dlib\Library\usr\bin;D:\Games\conda\envs\dlib\Library\bin;
D:\Games\conda\envs\dlib\Scripts;
D:\Games\conda\envs\dlib\bin;
D:\Games\conda\condabin;
D:\Games\conda;
D:\Games\conda\Library\mingw-w64\bin;
D:\Games\conda\Library\usr\bin;
D:\Games\conda\Library\bin;
D:\Games\conda\Scripts;
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0;
C:\Windows\System32\OpenSSH;
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.3.0;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0;
C:\WINDOWS\System32\OpenSSH;
C:\Program Files\PuTTY;
D:\Program Files\Git\cmd;
C:\Program Files\nodejs;C:\Program Files\dotnet;
C:\Users\Vasil\AppData\Local\Microsoft\WindowsApps;
C:\Users\Vasil\AppData\Local\Programs\Microsoft VS Code\bin;
C:\Users\Vasil\AppData\Local\GitHubDesktop\bin;
C:\Users\Vasil\AppData\Local\Microsoft\WindowsApps;
d:\Program Files\heroku\bin;C:\Users\Vasil\AppData\Roaming\npm;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;.

and cudnn64_7.dll is in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin

VasylKolomiiets avatar Apr 03 '21 09:04 VasylKolomiiets

I am facing the same error but on Python 3.9, I compiled it and everything seemed okay. But when i import dlib the before mentioned DLL error is displayed.

EDIT: I got Cuda to run in WSL 2, so I'll probably stick with it even if windows gets fixed. I'd suggest dropping windows all together once WSL 2 is outside of the Windows insider program

EDIT: after installing the expirmental CUDA for WSL driver it also worked on windows, but don't ask me why

hrkrx avatar Apr 30 '21 00:04 hrkrx

I had same issue when I compile dlib with CUDA enabled. In my case, the reason is the path of cuDNN.

"C:\Program Files\NVIDIA\CUDNN\v8.9.7.29\lib\cudnn.lib"

"import dlib" failed with that error.

When I move the filed under lib to "x64" as originally from cuDNN,zip

"C:\Program Files\NVIDIA\CUDNN\v8.9.7.29\lib\x64\cudnn.lib"

the problem solved.

mtsnrtkhr avatar Feb 05 '24 12:02 mtsnrtkhr