Cannot import name '_imaging' from 'PIL'
Question:
I’m trying to run this code:
import pyautogui
import time
from PIL import _imaging
from PIL import Image
import pytesseract
time.sleep(5)
captura = pyautogui.screenshot()
codigo = captura.crop((872, 292, 983, 337))
codigo.save(r'C:autobot_wwe_supercardimagenescodigo.png')
time.sleep(2)
pytesseract.pytesseract.tesseract_cmd = r'C:Program
FilesTesseract-OCRtesseract'
print(pytesseract.image_to_string(r'D:codigo.png'))
And this error pops up: ImportError: cannot import name ‘imaging’ from ‘PIL’ (C:UsersUsuarioAppDataRoamingPythonPython38site-packagesPIL_init.py)
I installed pillow in console with pip install pillow
I installed pytesseract in console with pip install pytesseract
Answers:
I needed Pillow in PyCharm with Python3.9.
Pillow was installed in Python3.8. Perhaps as user. PyCharm could find it with Py3.8, but not with Py3.9
This solved it for me:
sudo python3.9 -m pip install Pillow --upgrade
Upgrade it as sudo with that python version, which the script shall run with. Maybe, sudo is not needed, if you want to run it only in a virtual environment or as actual user.
PIL has some binary dependencies which are tied to the version of Python they were built against.
In my case, the solution was to edit the runtime settings of my Amazon Lambda function and change it to an older version of Python which matched my dev environment.
The same error will occur if pillow was installed for an incompatible CPU architecture.
I’m trying to run this code:
import pyautogui
import time
from PIL import _imaging
from PIL import Image
import pytesseract
time.sleep(5)
captura = pyautogui.screenshot()
codigo = captura.crop((872, 292, 983, 337))
codigo.save(r'C:autobot_wwe_supercardimagenescodigo.png')
time.sleep(2)
pytesseract.pytesseract.tesseract_cmd = r'C:Program
FilesTesseract-OCRtesseract'
print(pytesseract.image_to_string(r'D:codigo.png'))
And this error pops up: ImportError: cannot import name ‘imaging’ from ‘PIL’ (C:UsersUsuarioAppDataRoamingPythonPython38site-packagesPIL_init.py)
I installed pillow in console with pip install pillow
I installed pytesseract in console with pip install pytesseract
I needed Pillow in PyCharm with Python3.9.
Pillow was installed in Python3.8. Perhaps as user. PyCharm could find it with Py3.8, but not with Py3.9
This solved it for me:
sudo python3.9 -m pip install Pillow --upgrade
Upgrade it as sudo with that python version, which the script shall run with. Maybe, sudo is not needed, if you want to run it only in a virtual environment or as actual user.
PIL has some binary dependencies which are tied to the version of Python they were built against.
In my case, the solution was to edit the runtime settings of my Amazon Lambda function and change it to an older version of Python which matched my dev environment.
The same error will occur if pillow was installed for an incompatible CPU architecture.