Home > Blockchain >  ModuleNotFoundError when importing ‘keyboard’ in Python
ModuleNotFoundError when importing ‘keyboard’ in Python

Time:01-18

enter image description here

Here’s the story in a few words. Lottery game. Import keyboard. Linux root. ModuleNotFoundError. Why is there a ModuleNotFoundError on the import ‘keyboard’?

As you can see, it is an official module, so why am I getting a error?enter image description here

Here’s a code snippet of the import and what I am using it for.

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!”)

CodePudding user response:

(edited)

after a small search I found same problem and I found that the problem was solved by did the next install instruction

python -m pip install keyboard

after you install it close your ide then open it, it should be done.

CodePudding user response:

It looks like you have multiple Python environments. And you have selected the python interpreter which has not installed the keyboard module.

Could you check where you have installed the keyboard module through pip show keyboard? And which python interpreter you have selected from the bottom-left on the VSCode?

  •  Tags:  
  • Related