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

10

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)
Superb answered 31/7, 2018 at 22:57 Comment(4)
Maybe try pip3 install pynput (if you are using python 3)Randallrandan
Are you by chance using python3? How about pip3 install pynut?Rosalbarosalee
I am using python 3Superb
i did try with pip3 and not works yetSuperb
F
14

I had the same issue and I fixed it using:

python -m pip install pynput
Foliole answered 14/12, 2019 at 4:56 Comment(0)
S
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.

Subdual answered 16/1, 2019 at 22:4 Comment(0)
B
2

If you are using python 3.XX:

python3 -m pip install pynput
Beaudry answered 3/2, 2022 at 22:51 Comment(1)
This worked as the pre-processor needs to be python3Monday
E
1

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

Eldreda answered 10/7, 2019 at 19:6 Comment(0)
W
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...
Weigand answered 31/7, 2018 at 23:6 Comment(1)
I downloaded pynput with pip3 now, then at the prompt it works, but in pycharm and spyder not yetSuperb
F
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 .

Farman answered 30/1, 2020 at 2:49 Comment(0)
G
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.

Gazebo answered 29/8, 2020 at 8:2 Comment(0)
P
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"

Proliferation answered 30/8, 2022 at 17:17 Comment(0)
C
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.
Conglomeration answered 13/7, 2024 at 23:9 Comment(0)
D
-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

Duello answered 3/2, 2022 at 16:49 Comment(1)
If you try to run pip install pynput inside the interpreter, you get a syntax error, not No module named 'pynput'.Embassy

© 2022 - 2025 — McMap. All rights reserved.