1#----------------------------------------------------------------------------- 2# Copyright (c) 2013-2019, PyInstaller Development Team. 3# 4# Distributed under the terms of the GNU General Public License with exception 5# for distributing bootloader. 6# 7# The full license is in the file COPYING.txt, distributed with this software. 8#----------------------------------------------------------------------------- 9# If numpy is built with MKL support it depends on a set of libraries loaded 10# at runtime. Since PyInstaller's static analysis can't find them they must be 11# included manually. 12# 13# See 14# https://github.com/pyinstaller/pyinstaller/issues/1881 15# https://github.com/pyinstaller/pyinstaller/issues/1969 16# for more information 17import os 18import os.path 19import re 20from PyInstaller.utils.hooks import get_package_paths 21from PyInstaller import log as logging 22from PyInstaller import compat 23 24binaries = [] 25 26# look for libraries in numpy package path 27pkg_base, pkg_dir = get_package_paths('numpy.core') 28re_anylib = re.compile(r'\w+\.(?:dll|so|dylib)', re.IGNORECASE) 29dlls_pkg = [f for f in os.listdir(pkg_dir) if re_anylib.match(f)] 30binaries += [(os.path.join(pkg_dir, f), '.') for f in dlls_pkg] 31 32# look for MKL libraries in pythons lib directory 33# TODO: check numpy.__config__ if numpy is actually depending on MKL 34# TODO: determine which directories are searched by the os linker 35if compat.is_win: 36 lib_dir = os.path.join(compat.base_prefix, "Library", "bin") 37else: 38 lib_dir = os.path.join(compat.base_prefix, "lib") 39if os.path.isdir(lib_dir): 40 re_mkllib = re.compile(r'^(?:lib)?mkl\w+\.(?:dll|so|dylib)', re.IGNORECASE) 41 dlls_mkl = [f for f in os.listdir(lib_dir) if re_mkllib.match(f)] 42 if dlls_mkl: 43 logger = logging.getLogger(__name__) 44 logger.info("MKL libraries found when importing numpy. Adding MKL to binaries") 45 binaries += [(os.path.join(lib_dir, f), '.') for f in dlls_mkl] 46