python - pyinstaller 无法执行脚本,这是一个与 idle 一起使用的简单脚本
问题描述
我做了一个小工具来将 ctrl+win+right 箭头绑定到此代码中的一个键,它的 F2 问题是当我尝试使用 pyinstaller 使其成为我想要这个工具的朋友的可执行文件时,当我尝试打开exe它说无法执行脚本。但它与python idle一起正常工作,代码是:
from pynput.keyboard import Key , Controller
keyboard = Controller()
i=2
import keyboard
import time
def waitUntil(): #defines function
wU = True
while wU == True:
if not keyboard.is_pressed("F2"): #checks the condition
wU = False
else:
wU = True
while i == 2 :
if keyboard.is_pressed("F2") :
waitUntil()
keyboard.press("Ctrl+cmd+Right")
keyboard.release("Ctrl+cmd+Right")```
解决方案
在这里很难提供帮助,因为最终 Controller 没有名为“is_pressed()”的方法。
像这样清理你的代码:
from pynput.keyboard import Controller
keyboard = Controller()
def waitUntil(): #defines function
wU = True
while wU == True:
if not keyboard.is_pressed("F2"): #checks the condition
wU = False
else:
wU = True
while True :
if keyboard.is_pressed("F2") :
waitUntil()
keyboard.press("Ctrl+cmd+Right")
keyboard.release("Ctrl+cmd+Right")
运行时应该会出现以下错误:
Traceback (most recent call last):
File "/home/oubnouquestion.py", line 14, in <module>
if keyboard.is_pressed("F2") :
AttributeError: 'Controller' object has no attribute 'is_pressed'
至少这是我在 Linux 上使用最新版本的 pynput 得到的。因此,它甚至在我使用 Pyinstaller 之前就坏了。你确定这在空闲时有效吗?
推荐阅读
- angular - Webpack/Angular CLI - 如何在 HTML 中嵌入脚本而不是引用它们?
- spring - java.lang.ClassCastException:java.util.concurrent.FutureTask 无法转换为 com.model.Employee - Spring Batch Async
- google-apps-script - Google Apps 脚本递归调度触发器
- c# - .NET Core 发布编译错误
- java - 如何直接从 Java 调用 esql/c 程序
- wix - 如何使用 wix 3.11 burn 检测 .Net Framework 4.7.2
- python - GLTF在python中显示纹理
- jquery - 如何使用Jquery按名称获取“select”中的所有“option”值?
- sql-server - 想要在与其他数据相关的两个日期进行迭代
- c - 如何让 strcasecmp 比较字符串而不区分大小写