Python 3- pyautogui can't use screen shot functions - python

Python 3.6.4
Pillow (PIL) 5.0
OS Win 7
pyscreeze 0.1.13
I'm trying to utilize the screenshot functions with pyautogui, but encountering an issue.
import pyautogui
image = pyautogui.locateOnScreen('imagepath')
print(image)
I'm receiving the following error:
File "C:\Users\a7153\AppData\Local\Programs\Python\Python36\lib\site-packages\pyscreeze__init__.py", line 315, in _screenshot_win32
im = ImageGrab.grab()
NameError: name 'ImageGrab' is not defined
I've tried going to pyscreeze and directly importing from PIL (pillow) import ImageGrab, but with no luck. I've gone through the documentation and there doesn't seem to be anything on the issue. Does anyone have any suggestions?

Related

"Unused import: Image" error when trying to import a function

I downloaded Pillow using pip and am trying to import its Image package to use the rotate function that is in the Image package, but when I use
from PIL import Image
I get an
Unused import: Image
error along with a
found at PIL.Image 1
message. Does anybody know what this means or what I'm doing wrong?

Pillow package is required but i already have the latest version

So I'm trying to use pyautogui for a web scraper but I get this exception:
"The Pillow package is required to use this function"
I already have the latest version of Pillow
Here's the code:
import pyautogui
pyautogui.sleep(3)
pyautogui.press('win')
pyautogui.typewrite('google')
pyautogui.press('enter')
pyautogui.sleep(2)
pyautogui.typewrite('youtube.com')
pyautogui.press('enter')
coords = pyautogui.locateCenterOnScreen('new_tab.png')
pyautogui.click(coords)
Here's the line generating the error:
coords = pyautogui.locateCenterOnScreen('new_tab.png')
NOTE: I am using:
Windows 10
Python 3.9.0
VSCode
You can import Pillow at the start of your code:
import PIL
So I actually figured it out! Basically, I had to move the PIL package to site-packages, restart VSCode, and import PIL and now it works!

Pillow can't import

I have a Problem with the Pillow module.
So basically i tried the methods on this website installing it per pip install Pillow and also importing it per from PIL import Image and import PIL none of them worked
I would really appreciate it if someone helped
and thanks for reading. This is my code:
import pyautogui
import pyscreeze
from PIL import Image
lkchat = pyautogui.locateCenterOnScreen("python.png")
print ("lkchat")
I'm getting the following error message:
from PIL import Image
ImportError: No module named PIL
Kitty Star i would like to suggest you that replace PIL with pillow and then install pillow if your code does not run let me know the next error.

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. 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
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.

Anaconda python, PIL and imagingtk

Although this is a reasonably well documented problem, I can't find a solution.
I cannot import PIL and ImageTK.
Minimal example:
import Tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
image = Image.open('live.ppm')
photo = ImageTk.PhotoImage(image)
This produces the error:
File "C:\Anaconda\lib\site-packages\PIL\ImageTk.py", line 181, in paste
import _imagingtk
ImportError: No module named _imagingtk
I have tried:
conda install pillow
conda remove PIL
But no luck.
After uninstalling pillow and PIL:
pip install image
Fixed this issue.
Thanks for bringing this up. The ImageTk module is an extra extension that is not part of the default installation of Pillow.
This issue is long-standing: https://github.com/ContinuumIO/anaconda-issues/issues/150
We (Continuum) will investigate adding this module to our build process.
Try to verify the extension of the image, i got the same problem, and when i modified the extension the script worked

Categories

Resources