From 1fcb19492c5a262baed79669c21410257bd34295 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 17 Dec 2017 16:36:35 -0600 Subject: [PATCH] BUG: distutils: use AddDllDirectory where available This should reduce some DLL hell scenarios, namely scipy/scipy#8064. partial credits to @carlkl --- numpy/distutils/misc_util.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 93af7237522e..c308ad17eeff 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -2289,10 +2289,25 @@ def generate_config_py(target): # For gfortran+msvc combination, extra shared libraries may exist f.write(""" + import os -extra_dll_dir = os.path.join(os.path.dirname(__file__), '.libs') -if os.path.isdir(extra_dll_dir): - os.environ["PATH"] += os.pathsep + extra_dll_dir +import sys + +extra_dll_dir = os.path.join(os.path.dirname(__file__), 'extra-dll') + +if os.path.isdir(extra_dll_dir) and sys.platform == 'win32': + try: + from ctypes import windll, c_wchar_p + _AddDllDirectory = windll.kernel32.AddDllDirectory + _AddDllDirectory.argtypes = [c_wchar_p] + # Needed to initialize AddDllDirectory modifications + windll.kernel32.SetDefaultDllDirectories(0x1000) + except AttributeError: + def _AddDllDirectory(dll_directory): + os.environ["PATH"] += os.pathsep + dll_directory + + _AddDllDirectory(extra_dll_dir) + """) for k, i in system_info.saved_results.items():