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!
Related
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.
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.
I have created I python program which makes 100 screenshots, and saves them on a folder called img inside the OS folder Documents. It worked perfectly fine in my Linux Ubuntu, it did the 100 screenshots and saved them in the directory I wanted. Now, I created a new Linux user in the same Virtual Machine, and I ran the same python script.
It gives me this error: ImportError: No module named pyscreenshot
I have tried many times. It works in my other user, although in the new one it keeps giving me error. Is there any reason for this?
Thanks. The code is below:
import os
import pyscreenshot as ImageGrab
def photos(num):
for n in range(num):
s = str(n)
a = "../Documents/img/s" + s + ".png"
# grab fullscreen
im = ImageGrab.grab()
# save image file
im.save(a)
return True
Quick note: I am calling the function photos() from another file using import screenshot (the file is called 'screenshot.py')
try to install pyscreenshot for your user
pip install pyscreenshot
Just in case the answers provided above don't work, try using
sudo -H pip install pyscreenshot
I'm having issues using these three together. I believe wand is not recognizing the ImageMagick libraries but I'm not sure.
Environment:
Python 3.5.1 :: Anaconda 4.0.0 (64-bit)
Windows 7
Set up instructions I took:
Installed ImageMagick-6.9.4-Q8 (x64) with the "C/C++ development
headers options checked. (Installed to C:\Program
Files\ImageMagick-6.9.4-Q8)
Set MAGICK_HOME envar C:\Program Files\ImageMagick-6.9.4-Q8
Installed wand from pip
My code:
import wand
...
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
...
Traceback:
Traceback (most recent call last):
File ".\pdf_convert.py", line 31, in <module>
ret = pdf2jpg(f, target_file, 2480)
File ".\pdf_convert.py", line 10, in pdf2jpg
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
AttributeError: module 'wand' has no attribute 'image'
From everything I've seen I've followed the right setup instructions. I am using the 64 bit version of ImageMagick with the 64 bit version of Anaconda. This was working with me before until I started using Anaconda (before I was using regular 32 bit Python and 32 bit ImageMagick.)
Is there something I'm missing? Why is wand not working correctly?
Try this
from wand.image import Image
with Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
pass
Is there something I'm missing? Why is wand not working correctly?
I believe it is working as expected, and the original architect did not intend to allow top-package-level shortcuts (i.e. import wand). This kinda makes sense as wand integrates to IM with ctypes, and does not attempt to resolve libraries during setup.py.
You can modify the package to include the module shortcuts your expecting by adding the following.
# wand/__init__.py
import api
import color
import compat
import display
import drawing
import exceptions
import font
import image
import resource
import sequence
import version
But I wouldn't recommend this. The from package.module import Class is a lot more cleaner.
If you are using PIL.Image as well then use:
from wand.image import Image as wand_image_Image
import PIL
First the setup: Windows 8.1 64bit, Python 3.4 32bit.
I wanted to run the code here. So I installed comtypes
pip install comtypes
I then tried to run the code, i got
ImportError: cannot import name 'SpeechLib'
Then tried this code here to try and generate the needed SpeechLib module.
I am however still getting the same error, what should I try next?
Running these lines made it work:
from comtypes.client import CreateObject
engine = CreateObject("SAPI.SpVoice")
stream = CreateObject("SAPI.SpFileStream")
Output was:
# Generating comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4
# Generating comtypes.gen.SpeechLib
After this I got no import error anymore, as expected.