I am having issues installing one python 2 module (pynput).

In fact I typed the command:

sudo pip install pynput

It works when I try the following snippet:

import pynput

but when I type:

from pynput.keyboard import Key, Controller

The console returns:

Traceback (most recent call last):
  File "pynput.py", line 1, in <module>
    import pynput
  File "/home/IoTree/server/pynput.py", line 2, in <module>
    from pynput.keyboard import Key, Controller
ImportError: No module named keyboard

Could you please indicate me what's wrong and how to install this module proprely ?

Thank you.

EDIT: I tried with a different .py name (pt.py) and it still doesn't execute without error ..

  • Works for me. Are you sure there are no files and/or directories named pynput, pynput.py and pynput.pyc in the directory with the pt.py script? – Dirk Sep 10 '18 at 9:12
  • There's a pynput.pyc in the same directory but I wasn't worried about this file as I don't know what is it ... Should I delete it and then retry ? – Julien Blomme Sep 10 '18 at 9:35
  • Yes, delete it. It's a bytecode (+/- compiled) python file and it's a leftover from before you renamed the pynput.py script. – Dirk Sep 10 '18 at 9:55

Make sure that there are no files and/or directories with the same name of your script are still present in the directory with your script.]

This includes:

  • pynput
  • pynput.py (python script)
  • pynput.pyc (compiled bytecode python script )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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