5

My pyautogui program gives me the following error when I do:

position = pyautogui.locateCenterOnScreen(image, confidence=.7)

Error message:

File "C:\Users\ashis\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 144, in wrapper
    raise PyScreezeException('The Pillow package is required to use this function.')
pyscreeze.PyScreezeException: The Pillow package is required to use this function.

Other pyautogui functions are working properly only when I do pyautogui.locateCenterOnScreen() gives and error.

I already have pillow properly installed:

Requirement already satisfied: pillow in c:\users\ashis\appdata\local\programs\python\python310\lib\site-packages (9.0.0)

Can anyone help please? I am following a tutorial.

  • 3
    see paths in your messages - you have installed `pillow` in `Python 3.10` but you run code with `Python 3.9`. DIfferent version don't share modules. You have to install `pillow` in `Python 3.9`. If you use `python script.py` to run code then you can use `python -m pip install pillow` to install `pillow` for this version. – furas Feb 22 '22 at 00:31

4 Answers4

9

That's a small problem, just update your Pillow package.

pip install Pillow --upgrade

Pillow-4.2.1 was on my system, it upgraded to Pillow-5.1.0 and now everything works just fine.

Tanay
  • 561
  • 1
  • 3
  • 16
1
pip install pyautogui --upgrade
blackgreen
  • 34,072
  • 23
  • 111
  • 129
SosaGF
  • 11
  • 1
0

Here, is what worked for me

pip install pyscreeze

then,

import pyscreeze
position = pyscreeze.locateCenterOnScreen(image, confidence=.7)

Thanks,

0

I had the same problem, and just solved it with something so obvious yet silly I never would have expected it.

Pyautogui relies on Pyscreeze which relies on PIL. It will attempt to import from PIL, and if it fails, it will throw the error you are receiving. This could be because the PIL module is not installed on your system (in your case it clearly is), or because you are working in a different environment from where the module is installed.

In my case, I went directly into the Python310 folder in program files -> Lib -> site-packages, and sure enough, pil was in there. Yes, pil, as in lowercase. So I renamed the folder in uppercase and now it works. Sometimes it's the silliest thing...

Darkstar
  • 79
  • 1
  • 7