From 2a3cb83afc370b48a372125a489aa9c0557e6f02 Mon Sep 17 00:00:00 2001 From: Davis King Date: Wed, 17 Jun 2020 20:17:10 -0400 Subject: [PATCH] Make dlib/__init__.py know the paths to cuda that cmake used. Use those paths instead of relying on CUDA_PATH to be set. --- tools/python/CMakeLists.txt | 1 + tools/python/dlib/__init__.py | 13 ------------- tools/python/dlib/__init__.py.in | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) delete mode 100644 tools/python/dlib/__init__.py create mode 100644 tools/python/dlib/__init__.py.in diff --git a/tools/python/CMakeLists.txt b/tools/python/CMakeLists.txt index aca79a633..7b31f98f2 100644 --- a/tools/python/CMakeLists.txt +++ b/tools/python/CMakeLists.txt @@ -71,3 +71,4 @@ endif() pybind11_add_module(_dlib_pybind11 ${python_srcs}) target_link_libraries(_dlib_pybind11 PRIVATE dlib::dlib) +configure_file(${PROJECT_SOURCE_DIR}/dlib/__init__.py.in ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/dlib/__init__.py) diff --git a/tools/python/dlib/__init__.py b/tools/python/dlib/__init__.py deleted file mode 100644 index 2fb29c596..000000000 --- a/tools/python/dlib/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2020 Davis E. King (davis@dlib.net) -# License: Boost Software License See LICENSE.txt for the full license. - -try: - import os - # 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. - os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin')) -except (AttributeError,KeyError): - pass - -from _dlib_pybind11 import * -from _dlib_pybind11 import __version__, __time_compiled__ diff --git a/tools/python/dlib/__init__.py.in b/tools/python/dlib/__init__.py.in new file mode 100644 index 000000000..1fbc6ab62 --- /dev/null +++ b/tools/python/dlib/__init__.py.in @@ -0,0 +1,20 @@ +# 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.dirname(path)) + except (AttributeError,KeyError): + pass + +if '@DLIB_USE_CUDA@' == 'ON': + add_lib_to_dll_path('@cudnn@') + add_lib_to_dll_path('@CUDA_CUDART_LIBRARY@') + +from _dlib_pybind11 import * +from _dlib_pybind11 import __version__, __time_compiled__