13

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 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)
blackraven
  • 5,284
  • 7
  • 19
  • 45
Nilson Rodrigues
  • 149
  • 1
  • 1
  • 3

9 Answers9

12

I had the same issue and I fixed it using:

python -m pip install pynput
Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
Orionater
  • 121
  • 1
  • 4
2

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.

2

If you are using python 3.XX:

python3 -m pip install pynput
1

If you are using python3 you have to use pip3:
pip3 install pynput
or
python3 -m pip insall pynput

trxgnyp1
  • 317
  • 1
  • 10
0

If you used python install pynput, so please test your file by these steps. It can help you find your problem is from installation or there are multiple versions of python that cause this issue.

  1. open a terminal (command prompt in windows)
  2. go to the path your file located, it is possible by typing cd your/files/complete/path
  3. now type py script_name.py
  4. let us know that it worked or not, so we can suggest you other ways...
Hamid Yousefi
  • 198
  • 2
  • 9
0

your pycharm interpreter is not configured . near the run button there is a dropdown menu with the name of the python file written on it . in that dropdown menu is an option 'edit configurations' click on that . select the current file and change the interpreter on the python interpreter dropdown . hope this helps .

aritra
  • 31
  • 2
0
python -m pip install pynput

I was facing issue with my pycharm IDE with the version of 3.8. But the above command can solve this issue.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

Firstly, run the following command in the terminal:

pip install pynput

Then install the package through the PyCharm IDE:

In PyCharm, click File > Settings > Project: "projectname" > Python Interpreter > click the + > type "pynput" > click "Install Package"

Nicholas Obert
  • 1,235
  • 1
  • 13
  • 29
Chrille
  • 1
  • 3
-1

Actually you are doing inside the python interpreter and not the one with the system command line. Thats where the bug arises .

Performing pip install pynput in windows command line works perfect. check this

  • 1
    If you try to run `pip install pynput` inside the interpreter, you get a syntax error, not `No module named 'pynput'`. – Jack Deeth Feb 07 '22 at 17:25