14

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)
4
  • 1
    Maybe try pip3 install pynput (if you are using python 3) Commented Jul 31, 2018 at 22:58
  • Are you by chance using python3? How about pip3 install pynut?
    – Matt Clark
    Commented Jul 31, 2018 at 22:58
  • I am using python 3 Commented Jul 31, 2018 at 23:51
  • i did try with pip3 and not works yet Commented Aug 1, 2018 at 0:06

10 Answers 10

14

I had the same issue and I fixed it using:

python -m pip install pynput
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
  • This worked as the pre-processor needs to be python3 Commented Apr 29, 2022 at 8:18
1

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

0
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...
1
  • I downloaded pynput with pip3 now, then at the prompt it works, but in pycharm and spyder not yet Commented Aug 1, 2018 at 0:02
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 .

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.

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"

0

Use this command:

python -m pip install pynput
  • This command explicitly uses the Python interpreter to run pip as a module. It ensures that pip is run using the same Python environment as the python command.
  • This is useful when you have multiple Python versions installed, as it guarantees you're using the pip associated with the specific Python installation you're targeting.
-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
  • 1
    If you try to run pip install pynput inside the interpreter, you get a syntax error, not No module named 'pynput'.
    – Jack Deeth
    Commented Feb 7, 2022 at 17:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.