[GH-ISSUE #174] raise ImportErrorWhenRunningHook( PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_IPython required by hook #161

Closed
opened 2026-02-26 12:20:40 +03:00 by kerem · 0 comments
Owner

Originally created by @Roy-Carter on GitHub (May 20, 2021).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/174

Description of the issue

I have a python project that is split into a couple of directories and a main .py file that I call files from other directories in.
When filling up the information in the app and creating the conversion , it failed to finish the conversion properly and not even creating a directory .
I'm using onedirectory option with console based.

Context information (for bug reports)

  • Output of pyinstaller --version: 4.3
  • Version of Python: e.g. 3.8
  • Platform: Windows 10 [Version 10.0.19042.985]
  • Did you also try this on another platform? Does it work there?
    Haven't tried it , since i'm only using windows.

A minimal example program which shows the error

  1. I have a python directory with a main file and a couple directories that contain py files that I'm calling from my main .py
dir /b
.idea
Algorithm
CsvFiles
DBFiles
Output
ServerConnections
ServerStart

(and also a ServerMain.py in the root folder)
when importing the ServerMain,py and all the directories above as additional folders(each directory contains .py files / path to files
I come across the stacktrace i'll show below.

Stacktrace / full error message

Microsoft Windows [Version 10.0.19042.985]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Roy\Desktop\auto-py-to-exe>auto-py-to-exe
C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\config\loader.py:784: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if len(key) is 1:
C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\config\loader.py:793: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if len(key) is 1:
Traceback (most recent call last):
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 27, in <module>
    import resource
ModuleNotFoundError: No module named 'resource'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\__init__.py", line 49, in <module>
    from .terminal.embed import embed
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\embed.py", line 35, in <module>
    from IPython.terminal.ipapp import load_default_config
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\ipapp.py", line 47, in <module>
    from IPython.core.magics import ScriptMagics
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\__init__.py", line 22, in <module>
    from .execution import ExecutionMagics
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\execution.py", line 52, in <module>
    from IPython.utils.timing import clock, clock2
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 64, in <module>
    clocku = clocks = clock = time.clock
AttributeError: module 'time' has no attribute 'clock'
104747 ERROR: An error occurred while packaging
Traceback (most recent call last):
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 27, in <module>
    import resource
ModuleNotFoundError: No module named 'resource'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\pkgutil.py", line 493, in find_loader
    spec = importlib.util.find_spec(fullname)
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\importlib\util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\__init__.py", line 49, in <module>
    from .terminal.embed import embed
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\embed.py", line 35, in <module>
    from IPython.terminal.ipapp import load_default_config
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\ipapp.py", line 47, in <module>
    from IPython.core.magics import ScriptMagics
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\__init__.py", line 22, in <module>
    from .execution import ExecutionMagics
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\execution.py", line 52, in <module>
    from IPython.utils.timing import clock, clock2
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 64, in <module>
    clocku = clocks = clock = time.clock
AttributeError: module 'time' has no attribute 'clock'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 357, in get_module_file_attribute
    loader = pkgutil.find_loader(package)
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\pkgutil.py", line 499, in find_loader
    raise ImportError(msg.format(fullname, type(ex), ex)) from ex
ImportError: Error while finding loader for 'IPython.extensions' (<class 'AttributeError'>: module 'time' has no attribute 'clock')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\imphook.py", line 408, in _load_hook_module
    self._hook_module = importlib_load_source(
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\compat.py", line 637, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 962, in load_module
  File "<frozen importlib._bootstrap_external>", line 787, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py", line 34, in <module>
    datas += collect_data_files('IPython.extensions', include_py_files=True)
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 794, in collect_data_files
    pkg_base, pkg_dir = get_package_paths(package)
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 577, in get_package_paths
    file_attr = get_module_file_attribute(package)
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 376, in get_module_file_attribute
    raise ImportError('Unable to load module attribute') from e
ImportError: Unable to load module attribute

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Roy\Desktop\auto-py-to-exe\auto_py_to_exe\packaging.py", line 131, in package
    run_pyinstaller()
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 740, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 687, in build
    exec(code, spec_namespace)
  File "C:\Users\Roy\AppData\Local\Temp\tmp7j_0bcng\ServerMain.spec", line 7, in <module>
    a = Analysis(['C:/Users/Roy/Desktop/AnalyzerWithDB/pcapreader/ServerMain.py'],
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 245, in __init__
    self.__postinit__()
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\datastruct.py", line 159, in __postinit__
    self.assemble()
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 423, in assemble
    self.graph.process_post_graph_hooks()
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\analysis.py", line 367, in process_post_graph_hooks
    module_hook.post_graph()
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\imphook.py", line 447, in post_graph
    self._load_hook_module()
  File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\imphook.py", line 412, in _load_hook_module
    raise ImportErrorWhenRunningHook(
PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_IPython required by hook for module C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py. Please check whether module __PyInstaller_hooks_0_IPython actually exists and whether the hook is compatible with your version of C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py: You might want to read more about hooks in the manual and provide a pull-request to improve PyInstaller.
Originally created by @Roy-Carter on GitHub (May 20, 2021). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/174 ## Description of the issue I have a python project that is split into a couple of directories and a main .py file that I call files from other directories in. When filling up the information in the app and creating the conversion , it failed to finish the conversion properly and not even creating a directory . I'm using onedirectory option with console based. ## Context information (for bug reports) * Output of `pyinstaller --version`: ```4.3``` * Version of Python: e.g. 3.8 * Platform: Windows 10 [Version 10.0.19042.985] * Did you also try this on another platform? Does it work there? Haven't tried it , since i'm only using windows. ### A minimal example program which shows the error 1. I have a python directory with a main file and a couple directories that contain py files that I'm calling from my main .py ``` dir /b .idea Algorithm CsvFiles DBFiles Output ServerConnections ServerStart ``` (and also a ServerMain.py in the root folder) when importing the ServerMain,py and all the directories above as additional folders(each directory contains .py files / path to files I come across the stacktrace i'll show below. ### Stacktrace / full error message ``` Microsoft Windows [Version 10.0.19042.985] (c) Microsoft Corporation. All rights reserved. C:\Users\Roy\Desktop\auto-py-to-exe>auto-py-to-exe C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\config\loader.py:784: SyntaxWarning: "is" with a literal. Did you mean "=="? if len(key) is 1: C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\config\loader.py:793: SyntaxWarning: "is" with a literal. Did you mean "=="? if len(key) is 1: Traceback (most recent call last): File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 27, in <module> import resource ModuleNotFoundError: No module named 'resource' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 2, in <module> File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\__init__.py", line 49, in <module> from .terminal.embed import embed File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\embed.py", line 35, in <module> from IPython.terminal.ipapp import load_default_config File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\ipapp.py", line 47, in <module> from IPython.core.magics import ScriptMagics File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\__init__.py", line 22, in <module> from .execution import ExecutionMagics File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\execution.py", line 52, in <module> from IPython.utils.timing import clock, clock2 File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 64, in <module> clocku = clocks = clock = time.clock AttributeError: module 'time' has no attribute 'clock' 104747 ERROR: An error occurred while packaging Traceback (most recent call last): File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 27, in <module> import resource ModuleNotFoundError: No module named 'resource' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\pkgutil.py", line 493, in find_loader spec = importlib.util.find_spec(fullname) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\importlib\util.py", line 94, in find_spec parent = __import__(parent_name, fromlist=['__path__']) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\__init__.py", line 49, in <module> from .terminal.embed import embed File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\embed.py", line 35, in <module> from IPython.terminal.ipapp import load_default_config File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\terminal\ipapp.py", line 47, in <module> from IPython.core.magics import ScriptMagics File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\__init__.py", line 22, in <module> from .execution import ExecutionMagics File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\core\magics\execution.py", line 52, in <module> from IPython.utils.timing import clock, clock2 File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\IPython\utils\timing.py", line 64, in <module> clocku = clocks = clock = time.clock AttributeError: module 'time' has no attribute 'clock' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 357, in get_module_file_attribute loader = pkgutil.find_loader(package) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\pkgutil.py", line 499, in find_loader raise ImportError(msg.format(fullname, type(ex), ex)) from ex ImportError: Error while finding loader for 'IPython.extensions' (<class 'AttributeError'>: module 'time' has no attribute 'clock') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\imphook.py", line 408, in _load_hook_module self._hook_module = importlib_load_source( File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\compat.py", line 637, in importlib_load_source return mod_loader.load_module() File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper File "<frozen importlib._bootstrap_external>", line 962, in load_module File "<frozen importlib._bootstrap_external>", line 787, in load_module File "<frozen importlib._bootstrap>", line 265, in _load_module_shim File "<frozen importlib._bootstrap>", line 702, in _load File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py", line 34, in <module> datas += collect_data_files('IPython.extensions', include_py_files=True) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 794, in collect_data_files pkg_base, pkg_dir = get_package_paths(package) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 577, in get_package_paths file_attr = get_module_file_attribute(package) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 376, in get_module_file_attribute raise ImportError('Unable to load module attribute') from e ImportError: Unable to load module attribute During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Roy\Desktop\auto-py-to-exe\auto_py_to_exe\packaging.py", line 131, in package run_pyinstaller() File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\__main__.py", line 114, in run run_build(pyi_config, spec_file, **vars(args)) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 740, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 687, in build exec(code, spec_namespace) File "C:\Users\Roy\AppData\Local\Temp\tmp7j_0bcng\ServerMain.spec", line 7, in <module> a = Analysis(['C:/Users/Roy/Desktop/AnalyzerWithDB/pcapreader/ServerMain.py'], File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 245, in __init__ self.__postinit__() File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\datastruct.py", line 159, in __postinit__ self.assemble() File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\building\build_main.py", line 423, in assemble self.graph.process_post_graph_hooks() File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\analysis.py", line 367, in process_post_graph_hooks module_hook.post_graph() File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\imphook.py", line 447, in post_graph self._load_hook_module() File "C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\depend\imphook.py", line 412, in _load_hook_module raise ImportErrorWhenRunningHook( PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_IPython required by hook for module C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py. Please check whether module __PyInstaller_hooks_0_IPython actually exists and whether the hook is compatible with your version of C:\Users\Roy\AppData\Local\Programs\Python\Python38\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py: You might want to read more about hooks in the manual and provide a pull-request to improve PyInstaller. ```
kerem closed this issue 2026-02-26 12:20:40 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#161
No description provided.