简体   繁体   English

如何在Spyder上导入pyHook(Python 3.7)

[英]How to import pyHook on Spyder (Python 3.7)

I'm trying to use pyHook to get my image to change when I click on it with the mouse. 我尝试使用pyHook来更改我的图像,当我用鼠标单击它时。 But when I run my code, I get an error. 但是,当我运行代码时,会出现错误。

My Code: 我的代码:

from __future__ import print_function
from PIL import Image
import pyHook
import pythoncom

im = Image.open("H:/---------/Images/nature.jpg")


print(im.format, im.size, im.mode)

im.show()

def OnMouseEvent(event):
   im1 = Image.open("H:/----------/Images/nature.jpg").convert("L")

   im1.show()


hm = pyHook.HookManager()
hm.MouseLeft = OnMouseEvent
hm.HookMouse()
pythoncom.PumpMessages()

This is the error: 这是错误:

ModuleNotFoundError: No module named 'pyHook'

Screenshot: 屏幕截图: 我的代码和错误消息

Open up your terminal and type: 打开您的终端并输入:

pip3 install pyHook

It is case-sensitive. 区分大小写。 So type it properly. 因此,请正确输入。

After that, your python environment will have pyHook installed as a module and you will be able to successfully import in your code 之后,您的python环境将安装pyHook作为模块,您将能够成功import代码

EDIT: 编辑:

Try the following steps since you find the above did not work. 由于您发现上述内容无效,请尝试以下步骤。
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook 转到https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
Check your computer system and download the correct .whl file. 检查您的计算机系统并下载正确的.whl文件。
Open up your computer's terminal and navigate to your .whl file location. 打开计算机的终端,然后导航到.whl文件位置。 Example: cd C:\\Users\\ycx\\Desktop 示例: cd C:\\Users\\ycx\\Desktop
Type in: pip3 install pyHook‑1.5.1‑cp37‑cp37m‑win_amd64.whl This part should be your exact filename which you downloaded off the website. 键入: pip3 install pyHook‑1.5.1‑cp37‑cp37m‑win_amd64.whl这部分应该是您从网站上下载的确切文件名

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

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