[英]ModuleNotFoundError: No module named 'pynput' error on PyCharm
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'我不断收到错误信息——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.甚至在在线 IDE(例如 online-python.com)中有一个 go,但抛出了同样的错误。
There are similar threads on stackoverflow but none seem to have a solid fix/guide to solve this. stackoverflow 上有类似的线程,但似乎没有一个可靠的修复/指南来解决这个问题。
Make sure that you did install pynput:确保您确实安装了 pynput:
$ python3 -m pip install pynput
And config the Python interpreter in Pycharm correctly, to the global python3 or your specific venv.并将 Pycharm 中的 Python 解释器正确配置到全局 python3 或您的特定 venv。
A way that worked for me is installing pynput directing from inside PyCharm by using the terminal found on the bottom right.一种对我有用的方法是使用右下角的终端从 PyCharm 内部直接安装 pynput。
Inside the PyCharm terminal type: PyCharm内部端子类型:
pip3 install pynput
Note: This will only work if you already have Python3 installed on your system.注意:这只有在您的系统上已经安装了 Python3 时才有效。 Hope this helps: (:希望这可以帮助: (:
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.我刚开始使用 python,所以我不知道如何很好地使用 IDE。 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.在我的例子中,我使用的是虚拟环境,我重新使用了我上一个项目中使用的venv/
目录,它是venv39/
,我将它重命名为venv/
,并复制/粘贴到新项目,模块pytest
已经在它。
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
.然后我做了pip install pynput
,当我使用 vscode 或 PyCharm 编写代码时看起来很不错,没有模块缺少来自 IDE 的提示,但是,当我运行pytest
时,总是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.最后我猜pytest.exe
可能正在使用旧的python.exe
或类似的东西,所以我做了pip uninstall pytest
和pip install pytest
,然后问题就消失了。
Hope it help if you got the same case.如果你遇到同样的情况,希望对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.