0

I'm trying to use the keyboard module, but when I import it, I'm receiving a problem.

import keyboard

However, I get this error

     File "c:/Users/P/Code/test.py", line 1, in <module>
        import keyboard
      File "C:\Users\P\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\__init__.py", line 296, in <module>
        _listener = _KeyboardListener()
      File "C:\Users\P\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\_generic.py", line 17, in __init__
        self.queue = Queue()
    TypeError: __init__() missing 1 required positional argument: 'items'

Could someone please help me understand where I'm going wrong?

Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • 1
    What version of python are you using? I know there was a similar error when doing `import keyboard` in 2.7, it's possible it hasn't been fixed yet. The keyboard module is a bit of a PITA as far as bugs and workarounds. Also, how did you install `keyboard` initially? just `pip install keyboard`? EDIT: Whoops, I see you're using 3.7. Should've checked the path noted in the error message. – W. MacTurk Jun 16 '21 at 16:33
  • 2
    presumably you have a `queue.py` lying around that this module is picking up, instead of the [standard module](https://docs.python.org/3/library/queue.html) – Sam Mason Jun 16 '21 at 16:33
  • @W.MacTurk I'm using Python 3.7 and I installed keyboard by doing pip install keyboard – pavan-ka Jun 16 '21 at 16:38
  • What other imports are in your script? – W. MacTurk Jun 16 '21 at 16:53
  • @W.MacTurk there are none - this is the only one. – pavan-ka Jun 16 '21 at 17:18
  • @pavan-ka try putting `import queue; print(queue.__file__)` above the keyboard import, if this doesn't come from `site-packages` then that would confirm my suggestion above – Sam Mason Jun 16 '21 at 17:24
  • Sam Mason is correct; I just installed keyboard myself to check (never used it) and followed the traceback. I arrived at `C:/Users/.../Python39/Lib/queue.py`, and looked for the `Queue` class. At least with my installation, there are no arguments required (python 3.9, keyboard 0.13.5). If you have a different version of keyboard, maybe you could try updating it? I'm at a loss; the import works fine for me. – W. MacTurk Jun 16 '21 at 17:27

1 Answers1

1

It looks like the import needs another argument, which is pretty unusual.