简体   繁体   English

ModuleNotFoundError: 没有名为“Pynput”的模块

[英]ModuleNotFoundError: No module named 'Pynput

I installed it with pip install pynput (i also tried pip3 install , python -m pip install ) I am using vs code it also doesnt work with terminal pip list says i have pynput 1.7.1我用pip install pynput安装了它(我也试过pip3 install , python -m pip install )我正在使用 vs 代码它也不适用于终端 pip list 说我有 pynput 1.7.1

my code:我的代码:

import Pynput

from pynput.keyboard import Key, Listener


def on_press(key):
    print("{0} pressed".format(key))

def on_release(key):
    if key == Key.esc:
        return False



with Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()

The error is:错误是:

ModuleNotFoundError: No module named 'Pynput'

I hope the first line is some typing error and you are using import pynput and not Pynput.我希望第一行是一些输入错误,并且您使用的是 import pynput 而不是 Pynput。 Pls.请。 import correct module name导入正确的模块名称

Pls.请。 run the which python command and pip list to make sure the installation is correct.运行which python命令和pip list以确保安装正确。 Pls.请。 confirm if the python where you are executing this is same python where you have installed (use which python ).确认您执行此操作的 python 是否与您安装的 python 相同(使用which python )。 make sure you are executing in the same virtual env where you have installed basically.确保您在基本安装的同一个虚拟环境中执行。

Also, if your pip list shows the module in the list.此外,如果您的pip list显示pip list中的模块。 Open a python terminal there and run the import statement.在那里打开一个 python 终端并运行 import 语句。

如果您使用的是python3,请尝试:

pip3 install pynput

firstly, you need to check that it's installed correctly by the following command...首先,您需要通过以下命令检查它是否已正确安装...

pip install pynput

if you have mutiple versions of python installed then use this command (for python 3.x)...如果您安装了多个版本的python,请使用此命令(对于python 3.x)...

pip3 install pynput

If the output shows 'Requirement already satisfied' then you're good to go.如果输出显示“需求已经满足”,那么您就可以开始了。

Then go to IDLE Window and import the pynput module (to double-check) by typing this after the prompt:-然后转到空闲窗口并通过在提示后键入以下内容来导入 pynput 模块(以仔细检查):-

>>>import pynput

Note that you must type 'pynput' in lowercase only.请注意,您必须仅以小写形式键入“pynput”。

Wait for a few seconds.等待几秒钟。

Now if you don't encounter any error and get the prompt after importing, you can be 100% sure that the module pynput is installed correctly.现在,如果您没有遇到任何错误并在导入后得到提示,您就可以 100% 确定模块 pynput 已正确安装。

I hope this answer helped you.我希望这个答案对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM