Nilson Rodrigues
Nilson Rodrigues

Reputation: 159

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

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)

Upvotes: 14

Views: 106585

Answers (10)

Ebrahim Ramadan
Ebrahim Ramadan

Reputation: 39

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.

Upvotes: 0

Chrille
Chrille

Reputation: 1

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"

Upvotes: 0

trxgnyp1
trxgnyp1

Reputation: 428

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

Upvotes: 1

user7260398
user7260398

Reputation: 31

If you are using python 3.XX:

python3 -m pip install pynput

Upvotes: 2

dhanesh12twice
dhanesh12twice

Reputation: 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

Upvotes: -1

zakria bacha
zakria bacha

Reputation: 1

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.

Upvotes: 0

aritra
aritra

Reputation: 31

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 .

Upvotes: 0

Orionater
Orionater

Reputation: 141

I had the same issue and I fixed it using:

python -m pip install pynput

Upvotes: 14

Alexander Tereshkov
Alexander Tereshkov

Reputation: 119

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.

Upvotes: 2

Hamid Yousefi
Hamid Yousefi

Reputation: 223

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...

Upvotes: 0

Related Questions