def __init__(self): """ Load, unzip and initialize the Zip archive bundled with the executable. """ # Examine all items in sys.path and the one like /path/executable_name?117568 is the correct executable with # the bundled zip archive. Use this value for the ZlibArchiveReader class, and remove this item from sys.path. # It was needed only for FrozenImporter class. Wrong path from sys.path raises an ArchiveReadError exception. for pyz_filepath in sys.path: try: # Unzip zip archive bundled with the executable. self._pyz_archive = ZlibArchiveReader(pyz_filepath) # Verify the integrity of the zip archive with Python modules. # This is already done when creating the ZlibArchiveReader instance. #self._pyz_archive.checkmagic() # As no Exception was raised, we can assume that ZlibArchiveReader was successfully loaded. # Let's remove 'pyz_filepath' from sys.path. sys.path.remove(pyz_filepath) # Some runtime hook might need access to the list of available frozen modules. Let's make them # accessible as a set(). self.toc = set(self._pyz_archive.toc.keys()) # Return - no error was raised. trace("# PyInstaller: FrozenImporter(%s)", pyz_filepath) return except IOError: # Item from sys.path is not ZlibArchiveReader; let's try next one. continue except ArchiveReadError: # Item from sys.path is not ZlibArchiveReader; let's try next one. continue # sys.path does not contain the filename of the executable with the bundled zip archive. Raise import error. raise ImportError("Cannot load frozen modules.")
def __init__(self): """ Load, unzip and initialize the Zip archive bundled with the executable. """ # Examine all items in sys.path and the one like /path/executable_name?117568 # is the correct executable with bundled zip archive. Use this value # for the ZlibArchiveReader class and remove this item from sys.path. # It was needed only for FrozenImporter class. Wrong path from sys.path # Raises ArchiveReadError exception. for pyz_filepath in sys.path: # We need to acquire the interpreter's import lock here # because ZlibArchiveReader() seeks through and reads from the # zip archive. imp_lock() try: # Unzip zip archive bundled with the executable. self._pyz_archive = ZlibArchiveReader(pyz_filepath) # Verify the integrity of the zip archive with Python modules. # This is already done when creating the ZlibArchiveReader instance. #self._pyz_archive.checkmagic() # End this method since no Exception was raised we can assume # ZlibArchiveReader was successfully loaded. Let's remove 'pyz_filepath' # from sys.path. sys.path.remove(pyz_filepath) # Some runtime hook might need access to the list of available # frozen module. Let's make them accessible as a set(). self.toc = set(self._pyz_archive.toc.keys()) # Return - no error was raised. trace("# PyInstaller: FrozenImporter(%s)", pyz_filepath) return except IOError: # Item from sys.path is not ZlibArchiveReader let's try next. continue except ArchiveReadError: # Item from sys.path is not ZlibArchiveReader let's try next. continue finally: imp_unlock() # sys.path does not contain filename of executable with bundled zip archive. # Raise import error. raise ImportError("Can't load frozen modules.")
def __init__(self): """ Load, unzip and initialize the Zip archive bundled with the executable. """ for pyz_filepath in sys.path: imp_lock() try: try: self._pyz_archive = ZlibArchiveReader(pyz_filepath) sys.path.remove(pyz_filepath) self.toc = set(self._pyz_archive.toc.keys()) trace('# PyInstaller: FrozenImporter(%s)', pyz_filepath) return except IOError: continue except ArchiveReadError: continue finally: imp_unlock() raise ImportError("Can't load frozen modules.")