From 7fcb6c285d2ef6d91f37f07a8397efb10e5e697f Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 7 Jun 2020 16:42:44 -0400 Subject: [PATCH] Add an __init__.py file so we can add paths to CUDA libs on windows. --- setup.py | 3 ++- tools/python/CMakeLists.txt | 6 ++---- tools/python/dlib/__init__.py | 11 +++++++++++ tools/python/src/dlib.cpp | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 tools/python/dlib/__init__.py diff --git a/setup.py b/setup.py index ea40c32bb..a3f7bbe0e 100644 --- a/setup.py +++ b/setup.py @@ -229,13 +229,14 @@ setup( author_email='davis@dlib.net', url='https://github.com/davisking/dlib', license='Boost Software License', - ext_modules=[CMakeExtension('dlib','tools/python')], + ext_modules=[CMakeExtension('_dlib_pybind11','tools/python')], cmdclass=dict(build_ext=CMakeBuild, test=PyTest), zip_safe=False, # We need an older more-itertools version because v6 broke pytest (for everyone, not just dlib) tests_require=['pytest==3.8', 'more-itertools<6.0.0'], #install_requires=['cmake'], # removed because the pip cmake package is busted, maybe someday it will be usable. packages=['dlib'], + package_dir={'': 'tools/python'}, keywords=['dlib', 'Computer Vision', 'Machine Learning'], classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/tools/python/CMakeLists.txt b/tools/python/CMakeLists.txt index 12bd287cc..aca79a633 100644 --- a/tools/python/CMakeLists.txt +++ b/tools/python/CMakeLists.txt @@ -68,8 +68,6 @@ if(NOT ${DLIB_NO_GUI_SUPPORT}) list(APPEND python_srcs src/gui.cpp) endif() -pybind11_add_module(dlib_python ${python_srcs}) -target_link_libraries(dlib_python PRIVATE dlib::dlib) -# Set the output library name to dlib because that's what setup.py and distutils expects. -set_target_properties(dlib_python PROPERTIES OUTPUT_NAME dlib) +pybind11_add_module(_dlib_pybind11 ${python_srcs}) +target_link_libraries(_dlib_pybind11 PRIVATE dlib::dlib) diff --git a/tools/python/dlib/__init__.py b/tools/python/dlib/__init__.py new file mode 100644 index 000000000..b17f0d078 --- /dev/null +++ b/tools/python/dlib/__init__.py @@ -0,0 +1,11 @@ +from _dlib_pybind11 import * +from _dlib_pybind11 import __version__, __time_compiled__ + + +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 diff --git a/tools/python/src/dlib.cpp b/tools/python/src/dlib.cpp index 7dfdb0792..14e0d624e 100644 --- a/tools/python/src/dlib.cpp +++ b/tools/python/src/dlib.cpp @@ -37,7 +37,7 @@ void bind_line(py::module& m); void bind_gui(py::module& m); #endif -PYBIND11_MODULE(dlib, m) +PYBIND11_MODULE(_dlib_pybind11, m) { warn_about_unavailable_but_used_cpu_instructions();