import pynput
from pynput.keyboard import Key, Listener
def keyenter(key):
print("{0} pressed".format(key))
def keyexit(key):
if key == Key.esc:
return False
with Listener(keyenter=keyenter, keyexit=keyexit) as listener:
listener.join()
I keep getting the error -- ModuleNotFoundError: No module named 'pynput'
I've been at this for a while. Even had a go at online IDE's such as online-python.com, but threw the same error.
There are similar threads on stackoverflow but none seem to have a solid fix/guide to solve this.
Make sure that you did install pynput:
$ python3 -m pip install pynput
And config the Python interpreter in Pycharm correctly, to the global python3 or your specific venv.
I was stuck on a similar issues for almost two days. I was new to using python so I didn't know how to use the IDE well. All that I was missing was checking off "inherit global site-packages".
After that, it worked fine
I got this problem today and want to share my solution.
In my case I'm using virtual environment and I re-used the venv/
directory used in my last project, it was venv39/
and I renamed it to venv/
, and copy/paste to new project, the module pytest
was already in it.
Then I did pip install pynput
, it looked pretty good when I used vscode or PyCharm to wrote the code, no module missing prompt from the IDE, but, when I ran pytest
there's always no module named pynput
.
Finally I guess the pytest.exe
might be using the old python.exe
or something like that, so I did pip uninstall pytest
and pip install pytest
, then the problem was gone.
Hope it help if you got the same case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.