-1

When I install a module (now it's the keyboard module) in the Windows Command Prompt:

pip3 install keyboard

or

python -m pip install keyboard

or

pip install keyboard

This is the output. But when I try to import it, I get a ModuleNotFoundError. What is the problem? Could it be a PC space problem?

Elvis
  • 1
  • 2
  • 3
    Welcome to Stack Overflow. What is the directory name shown in the first screenshot? Therefore, which version of Python did you install `keyboard` for? What is the version of Python mentioned by the interpreter in the second screenshot? Do you see why this causes a problem? Also: [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Karl Knechtel Jan 17 '22 at 16:22
  • Karl just added what I was going to -- anything essential to answering the question (and that includes output logs in this case) should be included **as text** in the question itself. – Charles Duffy Jan 17 '22 at 16:23
  • 2
    From the screenshots it is clear that you install with python 3.10, and try to use it with python 3.9. You have to use the same python executable to install the package that you're intending to use it on. – Niko Föhr Jan 17 '22 at 16:24
  • The first output shows ``python310`` – Python version 3.10 - but the second shows Python 3.9. – MisterMiyagi Jan 17 '22 at 16:24
  • I used the C: directory, but also C:/Users/Elvis doesn't work – Elvis Jan 17 '22 at 16:25
  • @np8 Thank you, now it works – Elvis Jan 17 '22 at 16:26
  • quick fix would be to find the python executable you are using, inside python shell `import sys; print(sys.executable)` and then use ` -m pip install keyboard`. – Niko Föhr Jan 17 '22 at 16:26
  • As np8 just said.. simplified you are installing the module in the wrong place. Make sure you are in the correct Python (including version) when installing any module. Bonus tip use virtual environments if it's not an isolated system. – Cl0ud-l3ss Jan 17 '22 at 16:26
  • 1
    @CharlesDuffy generally I completely agree - you've probably seen my canned comment regarding this - but in this case having the screenshots (particularly of IDLE) was essential to solving the problem. It's doubtful that anyone copying code to paste in a question would include the `sys.version` string at the top. Very interesting conundrum... – MattDMo Jan 17 '22 at 16:38
  • As happens so often, there's no way I could have found the canonical duplicate myself. Thank you @Andras Deak. – Karl Knechtel Jan 17 '22 at 20:21

1 Answers1

0

You are using different python versions. Please make sure that you are using the same python version.

Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23