0

When I try to run a program that has import keyboard it gives me this error even though I installed it:

Traceback (most recent call last): File "C:\Users\Diana\Desktop\test file.py", line 1, in import keyboard ModuleNotFoundError: No module named 'keyboard'

Does anyone know why?

  • Are you using Python 2? If so this post may be helpfull https://stackoverflow.com/questions/35493899/python-traceback-most-recent-call-last – caesar-augustus Jun 18 '21 at 22:58
  • The python version where you installed your module should be the same python version you used to run your app. Check with `python -m pip` for the list of installed modules and `python -V` for versions. – Gino Mempin Jun 18 '21 at 23:12
  • Learn how to create and use virtual environments. Install and run from the same virtual env avoids these problems. – Gino Mempin Jun 18 '21 at 23:16
  • Your question is lacking a lot of detail, but my money would be on you having multiple Python installations. One of the most ridiculous things about Python (and it's not alone in this) is that a lot of projects handle package management by just installed Python again. Last time I checked my personal laptop, I had over 50 different installations of Python, including the 2 versions I actually installed manually. You need to make sure that the keyboard module is installed for the Python installation you're using to run the code. – Layne Bernardo Jun 19 '21 at 01:19

3 Answers3

0

It looks like you simply don't have the module named keyboard installed for the version of python that you're running the script with. Try running python -m pip install keyboard in a terminal outside of python to install the module, and try running the script again.

Assuming this is the module that's being referenced

Caleb McNevin
  • 135
  • 1
  • 12
  • I did but it still says that. –  Jun 18 '21 at 22:54
  • Sorry, missed that you said you do have it installed. It could be that the `pip` you ran installed the package for a different version of python that's also installed on your computer. Try running `python -m pip install keyboard` to ensure that pip installs the package in the right place. See [here](https://realpython.com/lessons/why-cant-python-find-my-modules/) – Caleb McNevin Jun 18 '21 at 22:59
  • When I did that it gave me this error while trying to install it on command prompt: Requirement already satisfied: keyboard in c:\users\diana\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (0.13.5) –  Jun 19 '21 at 17:04
0

You might have both Python 2 and Python 3 installed on your OS, which you can easily check by running this from your terminal:

pip --version

If the output ends with Python 2.X then you probably have two concurrent versions.

This implies that pip install keyboard would have installed the package for the respective Python version (2), i.e. you must explicitly point to pip3 implementation to get the package in the expected location:

pip3 install keyboard 
Max Shouman
  • 1,333
  • 1
  • 4
  • 11
  • That won't work. First I have a windows, and second I have the latest version of python installed. –  Jul 24 '21 at 17:17
-1

Pls check if you installed the module 'keyboard', If done, make sure you call the function.

Thesonter
  • 182
  • 12