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

问题描述 投票:0回答:2
Traceback (most recent call last):
  File "/home/cynthia0890/docs/lottery.py", line 3, ...
    import keyboard
ModuleNotFoundError: No module named 'keyboard'
root@penguin: /home/cynthia0890 #

用几句话来讲述这个故事。彩票游戏。导入键盘。 Linux 根。模块未找到错误。为什么导入“键盘”时出现 ModuleNotFoundError?

keyboard
模块是存储库中提供的官方模块,那么为什么我会收到错误?

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

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 visual-studio-code keyboard
2个回答
0
投票

(已编辑)

经过小规模搜索后,我发现了同样的问题,并且发现通过执行下一个安装指令解决了问题

python -m pip install keyboard

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


0
投票

您似乎有多个 Python 环境。并且您选择了未安装

keyboard
模块的 python 解释器。

您可以通过

keyboard
查看您安装了
pip show keyboard
模块吗?您在 VSCode 的左下角选择了哪个 Python 解释器?

© www.soinside.com 2019 - 2024. All rights reserved.