Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Error "No module named 'pynput'"? even after downloading with pip?

Tags:

python

pip

pynput

I downloaded the pynput in my windows with pip following the video: https://youtu.be/DTnz8wA6wpw

with cmd in administrator mode

pip install pynput

and when i run the code, the pycharm and spyder3 show the error:

Traceback (most recent call last):
  File "E:/Users/nilson/Dropbox/Python/PyCharm/auto/auto.py", line 1, in <module>
    from pynput.keyboard import Key, Controller
ModuleNotFoundError: No module named 'pynput'

Here is my code:

from pynput.keyboard import Key, Controller
import time

keyboard = Controller()

time.sleep(2)

for char in "sasdasdasda":
    keyboard.press(char)
    keyboard.release(char)
    time.sleep(0.12)
like image 456
Nilson Rodrigues Avatar asked Jul 31 '18 22:07

Nilson Rodrigues


People also ask

What is Pynput module in Python?

The package pynput. keyboard contains classes for controlling and monitoring the keyboard. pynput is the library of Python that can be used to capture keyboard inputs there the coolest use of this can lie in making keyloggers.

Does Pynput come with Python?

Since the pynput module does not come packaged with Python, you will have to manually download and install it using the pip package manager.

Does Pynput work on Linux?

On Linux, pynput uses X or uinput. When running under X, the following must be true: An X server must be running. The environment variable $DISPLAY must be set.


2 Answers

I had the same issue and I fixed it using:

python -m pip install pynput
like image 146
Orionater Avatar answered Sep 21 '22 02:09

Orionater


If it works at the prompt but not in the PyCharm, you probably need to install the package in the PyCharm. To do so, try the following:

  1. Open your .py file with Pycharm.
  2. Put your cursor next to the import pynput line.
  3. PyCharm will show the Lamp icon next to it (most definitely it will be RED)
  4. If it's RED, click the Lamp icon and select option "install pynput package".
  5. Once it's installed, run your script again.

I hope it will help. At least it helped me.

like image 37
Alexander Tereshkov Avatar answered Sep 20 '22 02:09

Alexander Tereshkov