Keyboard module gives overflow error when converting script to exe

本秂侑毒 提交于 2019-12-13 04:20:06

问题


I was trying to create a program to record keyboard keys using the keyboard module of Python. I want to create a standalone executable file for the program. So I used PyInstaller as well as other py to exe converters to convert my script to exe format but it always gives an Overflow Error on execution.

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 292, in listen
  File "site-packages\keyboard\_winkeyboard.py", line 560, in listen
  File "site-packages\keyboard\_winkeyboard.py", line 553, in prepare_intercept
ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert

What can I do to prevent it? Or is there any other way to create a standalone file to run a python script on other computers?


回答1:


It's a bug in the way the keyboard module imports the SetWindowsHookEx Windows API (ctypes defaults all params to int and SetWindowsHookEx's third param is a HINSTANCE, which on 64 bits is 64 bits wide). The (hackish) solution is to patch the library - add c_longlong to the imports from ctypes on line 32 of _winkeyboard.py, then uncomment the argtypes for SetWindowsHookEx on line 95 and change the third to c_longlong: SetWindowsHookEx.argtypes = [c_int, LowLevelKeyboardProc, c_longlong, c_int]



来源:https://stackoverflow.com/questions/51357940/keyboard-module-gives-overflow-error-when-converting-script-to-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!