繁体   English   中英

在 Python 中导入“键盘”时出现 ModuleNotFoundError

[英]ModuleNotFoundError when importing ‘keyboard’ in Python

在此处输入图像描述

这是几句话的故事。 彩票游戏。 导入键盘。 Linux 根。 模块未找到错误。 为什么在导入的“键盘”上有 ModuleNotFoundError?

如您所见,它是一个官方模块,为什么会出现错误? 在此处输入图像描述

这是导入的代码片段以及我使用它的目的。

import keyboard

if userNums == winningNums:
    print(“\nCongratulations! You won the jackpot!”)
    print(“Press M to return to the menu.”)
    if keyboard.is_pressed(“m”):
        printMenu()
    else:
        print(“Please press M to return to the menu!”)

(已编辑)

经过小小的搜索,我发现了同样的问题,我发现问题已通过下一个安装说明解决

python -m pip install keyboard

安装后关闭 ide 然后打开它,应该完成。

看起来您有多个 Python 环境。 并且您选择了没有安装keyboard模块的 python 解释器。

您能否通过pip show keyboard检查您在哪里安装了keyboard模块? 您从 VSCode 的左下角选择了哪个 python 解释器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM