我有一个pynput错误,当输入一个单引号到国际键盘的听众。我知道大多数人不会有这个问题,但我想处理这个案子。
我已经查过了,这似乎是pynput==1.6.8的一个问题,而且它是用pynput==1.7.0^修复的。
问题是,我使用pyinstaller将脚本转换为可执行文件,而且我喜欢pyinstaller,因为它还可以为macOS和Linux生成可执行文件,但是pyinstaller不适用于pynput==1.7.0,它使用的最新版本是pynput==1.6.8。
使用pynput==1.7.0时,生成的.exe提供描述性错误:Failed to execute script logger
是否有一种方法可以跳过组合撇号,而不是整个脚本崩溃与pynput==1.6.8?
这样简单的东西
我一直在使用pyinstaller --onefile -w logger.py来转换我的脚本。
我的脚本的代码:
def on_press(key):
global keys, count
print(f"key = {key}")
keys.append(key)
count += 1
# reset
if count >= 1:
count = 0
write_file(keys)
keys = []
def on_release(key):
if key == Key.esc:
return False
if __name__ == "__main__":
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()我收到的错误是:
Unhandled exception in listener callback
Traceback (most recent call last):
File "...\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 162, in inner
return f(self, *args, **kwargs)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 275, in _process
key = self._event_to_key(msg, vk)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 314, in _event_to_key
return KeyCode(**self._translate(
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_base.py", line 52, in __init__
self.combining = unicodedata.lookup(
KeyError: "undefined character name 'COMBINING APOSTROPHE'"
Traceback (most recent call last):
File "...\logger.py", line 54, in <module>
listener.join()
File "...\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 210, in join
six.reraise(exc_type, exc_value, exc_traceback)
File "...\Programs\Python\Python39\lib\site-packages\six.py", line 702, in reraise
raise value.with_traceback(tb)
File "...\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 162, in inner
return f(self, *args, **kwargs)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 275, in _process
key = self._event_to_key(msg, vk)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 314, in _event_to_key
return KeyCode(**self._translate(
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_base.py", line 52, in __init__
self.combining = unicodedata.lookup(
KeyError: "undefined character name 'COMBINING APOSTROPHE'"发布于 2022-03-14 03:50:18
如果不更新到更新版本的pynput,就无法修复这个问题。如果pyinstaller对此不起作用,那么您将需要使用其他的东西。我不知道任何linux可执行编译器,但您可以尝试一下用于mac的dmgbuild。
您也可以尝试像pyautogui这样的替代方法,但是它没有pynput所有相同的功能。这似乎是pyinstaller和pynput之间的一个问题,不幸的是,我看不出您可以做什么来解决这个问题。
https://stackoverflow.com/questions/67000341
复制相似问题