0

I'm trying to use pyHook to get my image to change when I click on it with the mouse. 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: My code and the error message

Elijah
  • 47
  • 5
  • 2
    Start here: https://stackoverflow.com/q/2325923/1531971 (among many others) Clearly, that module cannot be found. Also, you should show the entire backtrace for reference. –  Dec 17 '18 at 15:56

1 Answers1

2

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

EDIT:

Try the following steps since you find the above did not work.
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
Check your computer system and download the correct .whl file.
Open up your computer's terminal and navigate to your .whl file location. Example: 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.

ycx
  • 3,155
  • 3
  • 14
  • 26
  • This is exactly what I wrote – Elijah Dec 19 '18 at 15:10
  • pip3 install pyHook – Elijah Dec 19 '18 at 15:10
  • 1
    @Elijah I've added a new solution. Let me know if it works for you. Thanks – ycx Dec 19 '18 at 21:37
  • How do I know which one to download? – Elijah Jan 07 '19 at 15:08
  • I'm running windows 7 and my processor is Intel Core i7-2600 CPU. It is a 64-bit operating system. I know this but not which one is the correct download with this system. – Elijah Jan 07 '19 at 15:11
  • I downloaded one and typed this in, pip3 install pyHook-1.5.1-cp37-cp37m-win_amd64.whl, but it said I had a syntax error at the install part. – Elijah Jan 07 '19 at 15:32
  • @Elijah, could you update your question with screenshots of the command you entered, and the error? Also, I require you to run `python -V` in your command line to tell me your python version – ycx Jan 07 '19 at 15:40
  • I added a screenshot for you – Elijah Jan 09 '19 at 14:50
  • I'm using python 3.7 – Elijah Jan 09 '19 at 15:47
  • @Elijah You are using Windows, this means you need to open up your Command Prompt and follow the steps as outlined above in my answer. You can open up your Command Prompt by searching in your Start bar for `cmd.exe`. To navigate to your folder location, use `cd /filepathhere` – ycx Jan 09 '19 at 17:27