错误信息:

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并重新安装了键盘模块...
我的代码是(来源: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')

最佳答案

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

关于python - 如何修复与Python中的模块相关的此错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64731352/

10-11 23:11