键盘模块将脚本转换为exe时出现溢出错误

时间:2018-07-16 08:50:08

标签: python exe pyinstaller

我试图创建一个程序来使用Python的键盘模块记录键盘按键。 我想为程序创建一个独立的可执行文件。因此,我使用PyInstaller以及其他 py至exe转换器将脚本转换为exe格式,但执行时始终会出现溢出错误。

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

该如何预防? 还是有其他方法可以创建独立文件以在其他计算机上运行python脚本?

1 个答案:

答案 0 :(得分:1)

这是键盘模块导入SetWindowsHookEx Windows API的方式中的一个错误(ctypes将所有参数默认为int,SetWindowsHookEx的第三个参数是HINSTANCE,在64位上为64位宽)。 (骇人听闻的)解决方案是修补库-在c_longlong第32行的ctypes中将_winkeyboard.py添加到从SetWindowsHookEx.argtypes = [c_int, LowLevelKeyboardProc, c_longlong, c_int]的导入中,然后在第95行取消注释SetWindowsHookEx的argtype,并将第三个更改为c_longlong: =============================== Reward: 0.0 Steps: 0.0 Update: 1 Time: 1.2 Episodes: 1 Loss: 19796.0547 =============================== Reward: 13243.5 Steps: 100.0 Update: 3 Time: 5.33 Episodes: 2 Loss: 19431.1680 =============================== Reward: 13507.0 Steps: 100.0 Update: 6 Time: 5.56 Episodes: 3 Loss: 19586.0059 =============================== Reward: 13469.5 Steps: 100.0 Update: 9 Time: 5.96 Episodes: 4 Loss: 19398.0176 =============================== Reward: 13923.5 Steps: 100.0 Update: 12 Time: 6.34 Episodes: 5 Loss: 19539.2090 =============================== Reward: 13382.0 Steps: 100.0 Update: 15 Time: 6.57 Episodes: 6 Loss: 19461.4648 =============================== Reward: 14326.0 Steps: 100.0 Update: 18 Time: 6.89 Episodes: 7 Loss: 19103.9668 =============================== Reward: 15041.0 Steps: 100.0 Update: 21 Time: 7.16 Episodes: 8 Loss: 19470.4160 =============================== Reward: 15718.5 Steps: 100.0 Update: 24 Time: 7.52 Episodes: 9 Loss: 19668.2324 =============================== Reward: 14925.5 Steps: 100.0 Update: 27 Time: 8.0 Episodes: 10 Loss: 19771.4648 =============================== Reward: 15555.0 Steps: 100.0 Update: 30 Time: 8.12 Episodes: 11 Loss: 19788.6621 =============================== Reward: 14711.0 Steps: 100.0 Update: 33 Time: 8.52 Episodes: 12 Loss: 19724.0176 =============================== Reward: 15329.5 Steps: 100.0 Update: 36 Time: 9.03 Episodes: 13 Loss: 19551.4707 =============================== Reward: 15748.0 Steps: 100.0 Update: 39 Time: 9.17 Episodes: 14 Loss: 19516.3770 =============================== Reward: 15666.5 Steps: 100.0 Update: 42 Time: 9.39 Episodes: 15 Loss: 19426.6973 =============================== Reward: 15593.5 Steps: 100.0 Update: 45 Time: 9.85 Episodes: 16 Loss: 19327.2832 =============================== Reward: 15614.0 Steps: 100.0 Update: 48 Time: 10.13 Episodes: 17 Loss: 19158.5488 =============================== Reward: 15874.5 Steps: 100.0 Update: 51 Time: 10.47 Episodes: 18 Loss: 19061.7402 =============================== Reward: 15575.5 Steps: 100.0 Update: 54 Time: 10.68 Episodes: 19 Loss: 18895.0918 =============================== Reward: 15949.5 Steps: 100.0 Update: 57 Time: 11.01 Episodes: 20 Loss: 18741.6094