ModuleNotFoundError: No module named 'Pynput

2.8k Views Asked by At

I installed it with pip install pynput (i also tried pip3 install,python -m pip install) I am using vs code it also doesnt work with terminal pip list says i have pynput 1.7.1

my code:

import Pynput

from pynput.keyboard import Key, Listener


def on_press(key):
    print("{0} pressed".format(key))

def on_release(key):
    if key == Key.esc:
        return False



with Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()

The error is:

ModuleNotFoundError: No module named 'Pynput'
3

There are 3 best solutions below

0
On BEST ANSWER

I hope the first line is some typing error and you are using import pynput and not Pynput. Pls. import correct module name

Pls. run the which python command and pip list to make sure the installation is correct. Pls. confirm if the python where you are executing this is same python where you have installed (use which python). make sure you are executing in the same virtual env where you have installed basically.

Also, if your pip list shows the module in the list. Open a python terminal there and run the import statement.

1
On

If you are using python3, please try:

pip3 install pynput
0
On

firstly, you need to check that it's installed correctly by the following command...

pip install pynput

if you have mutiple versions of python installed then use this command (for python 3.x)...

pip3 install pynput

If the output shows 'Requirement already satisfied' then you're good to go.

Then go to IDLE Window and import the pynput module (to double-check) by typing this after the prompt:-

>>>import pynput

Note that you must type 'pynput' in lowercase only.

Wait for a few seconds.

Now if you don't encounter any error and get the prompt after importing, you can be 100% sure that the module pynput is installed correctly.

I hope this answer helped you.