【问题标题】:How to fix this Error related to Modules in Python?如何修复此与 Python 中的模块相关的错误?
【发布时间】:2021-02-20 04:11:43
【问题描述】:

错误信息:

keyboard.py", line 6, in <module>
    keyboard.write("GEEKS FOR GEEKS\n")
AttributeError: module 'keyboard' has no attribute 'write'
Press any key to continue . . .

我也尝试过升级pip并重新安装键盘模块......

MY CODE 是(来源:GEEKSFORGEEKS

#Using Keyboard module in Python
import keyboard

# It writes the content to output
keyboard.write("GEEKS FOR GEEKS\n")


# It writes the keys r, k and end of line
keyboard.press_and_release('shift + r, shift + k, \n')
keyboard.press_and_release('R, K')

# it blocks until ctrl is pressed
keyboard.wait('Ctrl')

【问题讨论】:

  • 你的操作系统是什么?我不确定在 windows 和 mac 但 linux 不允许你使用 keyboard.write() 除非你有管理员权限

标签: python module keyboard syntax-error


【解决方案1】:

如果您已将正在执行的脚本命名为keyboard.py,它将与您尝试导入的模块发生冲突。 尝试简单地更改您尝试运行的脚本的名称。

【讨论】:

  • 干得好,你很专心。
猜你喜欢
  • 2022-01-06
  • 1970-01-01
  • 1970-01-01
  • 2020-01-02
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-29
相关资源
最近更新 更多