# ------------------------------------------------------------------ """ pythonnet requires both clr.pyd and Python.Runtime.dll, but the latter isn't found by PyInstaller. """ import ctypes.util from PyInstaller.compat import is_win, getsitepackages from os.path import join, exists # pythonnet is available for all platforms using .NET and Mono, # but tested only on Windows using .NET. if is_win: pyruntime = 'Python.Runtime' library = ctypes.util.find_library(pyruntime) datas = [] if library: datas = [(library, '.')] else: # find Python.Runtime.dll in pip-installed pythonnet package for sitepack in getsitepackages(): library = join(sitepack, pyruntime + '.dll') if exists(library): datas = [(library, '.')] if not datas: raise Exception(pyruntime + ' not found')
#----------------------------------------------------------------------------- # Copyright (c) 2013, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- import os from PyInstaller.compat import getsitepackages, is_darwin, is_win from PyInstaller.utils.hooks import qt4_menu_nib_dir # On Windows system PATH has to be extended to point to the PySide directory. # The PySide directory contains Qt dlls. We need to avoid including different # version of Qt libraries when there is installed another application (e.g. QtCreator) if is_win: from PyInstaller.utils.win32.winutils import extend_system_path extend_system_path([os.path.join(x, 'PySide') for x in getsitepackages()]) # For Qt to work on Mac OS X it is necessary to include directory qt_menu.nib. # This directory contains some resource files necessary to run PyQt or PySide # app. if is_darwin: datas = [ (qt4_menu_nib_dir(), ''), ]
#----------------------------------------------------------------------------- import os from PyInstaller.utils.hooks import ( get_module_attribute, is_module_satisfies, qt5_menu_nib_dir) from PyInstaller.compat import getsitepackages, is_darwin, is_win # On Windows system PATH has to be extended to point to the PyQt5 directory. # The PySide directory contains Qt dlls. We need to avoid including different # version of Qt libraries when there is installed another application (e.g. QtCreator) if is_win: from PyInstaller.utils.win32.winutils import extend_system_path extend_system_path([os.path.join(x, 'PyQt5') for x in getsitepackages()]) # In the new consolidated mode any PyQt depends on _qt hiddenimports = ['sip', 'PyQt5.Qt'] # For Qt<5.4 to work on Mac OS X it is necessary to include `qt_menu.nib`. # This directory contains some resource files necessary to run PyQt or PySide # app. if is_darwin: # Version of the currently installed Qt 5.x shared library. qt_version = get_module_attribute('PyQt5.QtCore', 'QT_VERSION_STR') if is_module_satisfies('Qt < 5.4', qt_version): datas = [(qt5_menu_nib_dir(), '')]
#----------------------------------------------------------------------------- """ pythonnet requires both clr.pyd and Python.Runtime.dll, but the latter isn't found by PyInstaller. """ import ctypes.util from PyInstaller.compat import is_win, getsitepackages from os.path import join, exists # pythonnet is available for all platforms using .NET and Mono, # but tested only on Windows using .NET. if is_win: pyruntime = 'Python.Runtime' library = ctypes.util.find_library(pyruntime) datas = [] if library: datas = [(library, '.')] else: # find Python.Runtime.dll in pip-installed pythonnet package for sitepack in getsitepackages(): library = join(sitepack, pyruntime + '.dll') if exists(library): datas = [(library, '.')] if not datas: raise Exception(pyruntime + ' not found')
def import_pywin32_module(module_name): """ Import and return the PyWin32 module with the passed name. When imported, the `pywintypes` and `pythoncom` modules both internally import dynamic libraries (e.g., `pywintypes.py` imports `pywintypes34.dll` under Python 3.4). The Anaconda Python distribution for Windows installs these libraries to non-standard directories, resulting in `"ImportError: No system module 'pywintypes' (pywintypes34.dll)"` exceptions. This function catches these exceptions, searches for these libraries, adds their directories to `sys.path`, and retries. Parameters ---------- module_name : str Fully-qualified name of this module. Returns ---------- types.ModuleType The desired module. """ module = None try: module = __import__(module_name, globals={}, locals={}, fromlist=['']) except ImportError as exc: if str(exc).startswith('No system module'): # True if "sys.frozen" is currently set. is_sys_frozen = hasattr(sys, 'frozen') # Current value of "sys.frozen" if any. sys_frozen = getattr(sys, 'frozen', None) # Force PyWin32 to search "sys.path" for DLLs. By default, PyWin32 only searches "site-packages\win32\lib", # "sys.prefix", and Windows system directories (e.g., "C:\Windows\System32"). This is an ugly hack, but # there is no other way. sys.frozen = '|_|GLYH@CK' # If isolated to a venv, the preferred site.getsitepackages() function is unreliable. Fall back to searching # "sys.path" instead. if compat.is_venv: sys_paths = sys.path else: sys_paths = compat.getsitepackages() for sys_path in sys_paths: # Absolute path of the directory containing PyWin32 DLLs. pywin32_dll_dir = os.path.join(sys_path, 'pywin32_system32') if os.path.isdir(pywin32_dll_dir): sys.path.append(pywin32_dll_dir) try: module = __import__(name=module_name, globals={}, locals={}, fromlist=['']) break except ImportError: pass # If "sys.frozen" was previously set, restore its prior value. if is_sys_frozen: sys.frozen = sys_frozen # Else, undo this hack entirely. else: del sys.frozen # If this module remains unimportable, PyWin32 is not installed. Fail. if module is None: raise return module