无法从 'PIL' 导入名称“_imaging”

Cannot import name '_imaging' from 'PIL'

我正在尝试 运行 此代码:

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_supercard\imagenes\codigo.png')
time.sleep(2)
pytesseract.pytesseract.tesseract_cmd = r'C:\Program     
Files\Tesseract-OCR\tesseract'
print(pytesseract.image_to_string(r'D:\codigo.png'))

然后弹出这个错误:ImportError: cannot import name 'imaging' from 'PIL' (C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\PIL_init.py)

我用 pip install pillow 在控制台安装了 pillow

我使用 pip install pytesseract 在控制台中安装了 pytesseract

似乎很多 PIL ImportErrors 都可以简单地通过根据此 source and your specific problem can be found here.source and your specific problem can be found here.

卸载并重新安装 Pillow 来简单地修复

试试这三个命令:

pip uninstall PIL
pip uninstall Pillow
pip install Pillow

我需要 枕头 PyCharm 和 Python3.9。 Pillow 已安装在 Python3.8。也许作为用户。 PyCharm 可以用 Py3.8 找到它,但不能用 Py3.9

这为我解决了:

sudo python3.9 -m pip install Pillow --upgrade

使用该 python 版本将其升级为 sudo,脚本应 运行 使用该版本。也许,sudo 是不需要的,如果你想 运行 它只是在虚拟环境中或作为实际用户。