AskGPT
AskGPT copied to clipboard
The Python `keyboard` module is incompatible with macOS Ventura
run anywhere也能正常调起Alfred,gpt关键词也没问题。
但就是没响应;
实测api-key和代理接口没问题。
这个脚本使用的是stream模式,你要确保你的代理支持stream。
可以尝试在 Terminal 中运行 <Alfred 环境变量中的 Python 路径> -c "import keyboard; keyboard.write('test')"
, 看 'test' 有没有被输出。
可能是因为 Python 的 keyboard 包太久没有更新,不兼容新版本的 macOS。
终端中运行确实不能正确打印 “test”。应该是这个原因了。我的系统是macOS Ventura 13.1;
@zhuiyue132 谢谢!
能否帮忙尝试下
import subprocess
applescript = """
tell application "System Events" to keystroke "test"
"""
subprocess.call(['osascript', '-e', applescript])
能否在 Ventura 下运行。
会尽快修复。
@zhuiyue132 谢谢!
能否帮忙尝试下
import subprocess applescript = """ tell application "System Events" to keystroke "test" """ subprocess.call(['osascript', '-e', applescript])
能否在 Ventura 下运行。
会尽快修复。
这段代码可以在Ventura 下运行。运行效果如图:
@zhuiyue132 好的,会尽快修复。
There are two alternatives for the Python keyboard
module: pynput and PyAutoGUI.
Is there anyone who can test which one is compatible with macOS Ventura?
@zhuiyue132 谢谢!
能否帮忙尝试下
import subprocess applescript = """ tell application "System Events" to keystroke "test" """ subprocess.call(['osascript', '-e', applescript])
能否在 Ventura 下运行。
会尽快修复。
这个方案不支持中文。
There are two alternatives for the Python
keyboard
module: pynput and PyAutoGUI.Is there anyone who can test which one is compatible with macOS Ventura?
两个包我都试了一下,存在一个相同的问题:输出结果包含同时包含中英文时,输入法不能及时切换,导致输出乱七八糟,见下方视频。输出纯英文或纯中文(需要把自带的打印关掉)无此问题。
https://user-images.githubusercontent.com/26954775/234206988-82063a56-9b9e-46ef-bb6c-c4eecfbeca4f.mp4
@zhuiyue132 谢谢!
在 macOS Monterey 使用 keyboard
+ 系统自带输入法 没有类似问题,输出示例如下:
>>> js 冒泡排序带中文注释
function bubbleSort(arr) {
const len = arr.length; // 获取数组长度,用于控制循环次数
for (let i = 0; i < len - 1; i++) { // 外层循环控制排序次数,每次循环可以确保一个元素位置正确
for (let j = 0; j < len - 1 - i; j++) { // 内层循环用于比较相邻的两个元素的大小,并交换位置
if (arr[j] > arr[j + 1]) { // 如果当前元素比下一位元素大,则交换位置
const temp = arr[j]; // 用临时变量存储当前元素的值
arr[j] = arr[j + 1]; // 将下一位元素的值赋给当前元素
arr[j + 1] = temp; // 将临时变量中存储的当前元素的值赋给下一位元素
}
}
}
return arr; // 返回排序后的数组
}
// 示例用法:
const arr = [3, 5, 1, 2, 4];
console.log(bubbleSort(arr)); // 输出 [1, 2, 3, 4, 5]
[Generated by ChatGPT, 2023-04-25 15:48:51]
除了 pynput 和 PyAutoGUI 外,还有一个可能的解决方案是,用 https://github.com/boppreh/keyboard/pull/587 替换默认的 keyboard
。
从 GitHub Repository 安装 Python 包的命令如下:
pip uninstall keyboard
pip install git+https://github.com/0xGosu/keyboard.git
@zhuiyue132 谢谢!
在 macOS Monterey 使用
keyboard
+ 系统自带输入法 没有类似问题,输出示例如下:>>> js 冒泡排序带中文注释 function bubbleSort(arr) { const len = arr.length; // 获取数组长度,用于控制循环次数 for (let i = 0; i < len - 1; i++) { // 外层循环控制排序次数,每次循环可以确保一个元素位置正确 for (let j = 0; j < len - 1 - i; j++) { // 内层循环用于比较相邻的两个元素的大小,并交换位置 if (arr[j] > arr[j + 1]) { // 如果当前元素比下一位元素大,则交换位置 const temp = arr[j]; // 用临时变量存储当前元素的值 arr[j] = arr[j + 1]; // 将下一位元素的值赋给当前元素 arr[j + 1] = temp; // 将临时变量中存储的当前元素的值赋给下一位元素 } } } return arr; // 返回排序后的数组 } // 示例用法: const arr = [3, 5, 1, 2, 4]; console.log(bubbleSort(arr)); // 输出 [1, 2, 3, 4, 5] [Generated by ChatGPT, 2023-04-25 15:48:51]
除了 pynput 和 PyAutoGUI 外,还有一个可能的解决方案是,用 boppreh/keyboard#587 替换默认的
keyboard
。从 GitHub Repository 安装 Python 包的命令如下:
pip uninstall keyboard pip install git+https://github.com/0xGosu/keyboard.git
修复版的keyboard安装失败。会不会因为我是Apple 芯片的问题?
我也 Apple 芯片。URL 似乎不太对?我的输出前几行是这样的。
(base) name@mac ~> pip install git+https://github.com/0xGosu/keyboard.git
Collecting git+https://github.com/0xGosu/keyboard.git
Cloning https://github.com/0xGosu/keyboard.git to /private/var/folders/0r/10nyc1zs4md_ddh4570xms4c0000gn/T/pip-req-build-mm6jqs9p
Running command git clone -q https://github.com/0xGosu/keyboard.git /private/var/folders/0r/10nyc1zs4md_ddh4570xms4c0000gn/T/pip-req-build-mm6jqs9p
麻烦问下,这个大概多久能支持Ventura系统呀
将python升级到Python 3.11.5后,可以在Ventura上正常使用。