Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update __init__.py.in #2515

Merged
merged 1 commit into from
Feb 18, 2022
Merged

Update __init__.py.in #2515

merged 1 commit into from
Feb 18, 2022

Conversation

DrRyanHuang
Copy link
Contributor

When I run:

import dlib
>>> import dlib

---------------------------------
Traceback (most recent call last):

  File "xxxxx.py", line 1, in <module>
    import dlib

  File "xxxxx\lib\site-packages\dlib\__init__.py", line 21, in <module>
    add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib/cudnn.lib')

  File "xxxxx\lib\site-packages\dlib\__init__.py", line 11, in add_lib_to_dll_path
    os.add_dll_directory(os.path.join(os.path.dirname(path), '../../bin'))

  File "xxxxx\lib\os.py", line 1109, in add_dll_directory
    cookie = nt._add_dll_directory(path)

FileNotFoundError: [WinError 2] The system cannot find the file specified : 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib\\../../bin'

My __init__.py is as follow:

# Copyright (C) 2020  Davis E. King (davis@dlib.net)
# License: Boost Software License   See LICENSE.txt for the full license.

def add_lib_to_dll_path(path):
    """ On windows you must call os.add_dll_directory() to allow linking to external DLLs.  See
    https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew.  This function adds the folder
    containing path to the dll search path. 
    """
    try:
        import os
        os.add_dll_directory(os.path.join(os.path.dirname(path), '../../bin'))
        os.add_dll_directory(os.path.join(os.path.dirname(path), '../bin'))
        
    except (AttributeError,KeyError):
        pass
    # except (AttributeError, KeyError, FileNotFoundError):
    #     pass


if 'ON' == 'ON':
    add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib/cudnn.lib')
    add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib/x64/cudart.lib')

from _dlib_pybind11 import *
from _dlib_pybind11 import __version__, __time_compiled__

So, to add FileNotFoundError is needed.

@davisking
Copy link
Owner

Thanks :)

@davisking davisking merged commit 7e942ba into davisking:master Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants