Exception with Python 3.6.5 64 bit and pyinstaller
See original GitHub issueWhen using keyboard with python 3.6.5 64 bit and running inside of pyinstaller, this error is returned:
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.py", line 916, in _bootstrap_inner
File "threading.py", line 864, in run
File "site-packages\keyboard\__init__.py", line 296, in listen
File "site-packages\keyboard\_winkeyboard.py", line 562, in listen
File "site-packages\keyboard\_winkeyboard.py", line 555, in prepare_intercept
ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert
I found a couple of other issues on other projects describing the same issue: https://github.com/rene-aguirre/pywinusb/issues/30 https://github.com/jaraco/jaraco.windows/issues/7 https://stackoverflow.com/questions/44163105/python-3-5-1-amd64-ctypes-argumenterror-argument-1-class-overflowerror https://bitbucket.org/pyglet/pyglet/issues/147/ctypesargumenterror-argument-4-int-too
Not sure exactly how to solve this for keyboard, but I am using 0.13.1. This error does not appear for me when I force using 32 bit Python in pyinstaller. I also only see the error inside of pyinstaller, not when just running a project normally with Python 3.6.5 64 bit.
This is all being done on Windows 10.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
Top GitHub Comments
I figured out the easy workaround finally, @GbeTech this should work for you too.
in
keyboard\_winkeyboard.py
line 555 replacekeyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, GetModuleHandleW(None), None)
withkeyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, ctypes.c_ulonglong(GetModuleHandleW(None)), None)
GetModuleHandleW
needs to be wrapped inctypes.c_ulonglong
or you get the overflow error. If the problem happens in any other modules you come across, the fix should be similar.I’m not sure if this is the right way to do it @boppreh, (perhaps it should be specified earlier, or conditional on 32 vs 64 bit, but it works for my system).
Thank you for the in-depth report, I’m working on it.