本文介绍了将脚本转换为exe时,键盘模块给出了溢出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

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

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

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?

推荐答案

这是键盘模块导入SetWindowsHookEx Windows API的方式中的一个错误(ctypes将所有参数默认设置为int,SetWindowsHookEx的第三个参数是HINSTANCE,它使用64位是64位宽). (拙劣的)解决方案是修补库-在_winkeyboard.py的第32行的ctypes中将c_longlong添加到导入中,然后在第95行的SetWindowsHookEx的argtypes中取消注释,并将第三个更改为c_longlong:SetWindowsHookEx.argtypes = [c_int, LowLevelKeyboardProc, c_longlong, c_int]

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]

这篇关于将脚本转换为exe时,键盘模块给出了溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:29
查看更多