Pyinstaller: Is there an easy way to disable one of Pyinstaller's built-in runtime hooks?

Created on 10 Aug 2016  路  4Comments  路  Source: pyinstaller/pyinstaller

Hello,

I want to completely disable the tkinter module and I tried doing the recommended way:
from PyInstaller.compat import modname_tkinter
excludedimports=[modname_tkinter]
but as stated in the documentation as long as someone else (including Pyinstaller's built-in hooks) imports this module it will not be excluded from the build.
So now I want to disable the pyi_rth__tkinter.py hook because I saw other modules like PIL that use tkinter. Is this possible?

support

Most helpful comment

Ok, I'll accept that.
And I must correct myself about fixing my problem. Build procedure with pyinstaller is successful and when I execute my exe on the build machine - it's ok. When I package it and install on a target machine I get the same error again:
File "site-packages\PyInstaller\loader\rthooks\pyi_rth__tkinter.py", line 28, in <module> FileNotFoundError: Tcl data directory "C:\XXXX\tcl" not found. Failed to execute script pyi_rth__tkinter

Which means someone is still importing tkinter after all?

All 4 comments

I'm not aware of any way to disable the runtime hooks. But to reach your aim to exclude tkinter: The way for this is to pass --exclude-module on the command line. This should overwrite any imports within your program.

Thanks, this worked for me, but it's strange that excludedimports didn't. Don't you think?

but it's strange that excludedimports didn't. Don't you think?

No, this is how it is expected to work. Imagine your application relies on tkinter and the hook of some package you are using is excluding tkinter (e.g. since it is only optional for this package). Would you want tkinter to be excluded by the hook?

Ok, I'll accept that.
And I must correct myself about fixing my problem. Build procedure with pyinstaller is successful and when I execute my exe on the build machine - it's ok. When I package it and install on a target machine I get the same error again:
File "site-packages\PyInstaller\loader\rthooks\pyi_rth__tkinter.py", line 28, in <module> FileNotFoundError: Tcl data directory "C:\XXXX\tcl" not found. Failed to execute script pyi_rth__tkinter

Which means someone is still importing tkinter after all?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

longqzh picture longqzh  路  48Comments

sean0x42 picture sean0x42  路  35Comments

matysek picture matysek  路  39Comments

giumas picture giumas  路  35Comments

phirst picture phirst  路  40Comments