Skip to content

Commit

Permalink
Add an __init__.py file so we can add paths to CUDA libs on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
davisking committed Jun 7, 2020
1 parent 53b6ea3 commit 7fcb6c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,14 @@ def read_entire_file(fname):
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',
Expand Down
6 changes: 2 additions & 4 deletions tools/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

11 changes: 11 additions & 0 deletions tools/python/dlib/__init__.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tools/python/src/dlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 7fcb6c2

Please sign in to comment.