我正在学习一门名为“自动处理无聊的东西”的课程,最后一部分是关于pyautogui和枕头的。我可以成功地导入pyautogui和pillow,并且我可以使用pyautogui的击键功能,但是如果我试图在pyautogui中运行一个涉及pillow的功能,它会给我这个错误。我尝试运行的函数是pyautogui.screenshot()
File "<input>", line 1, in <module>
File "C:\Users\offic\PycharmProjects\test\venv\Lib\site-packages\pyscreeze\__init__.py", line 134, in wrapper
raise PyScreezeException('The Pillow package is required to use this function.')
pyscreeze.PyScreezeException: The Pillow package is required to use this function.
下面是pyscreeze中的代码,它确定pillow是否在那里
try:
from PIL import Image
from PIL import ImageOps
from PIL import ImageDraw
if sys.platform == 'win32': # TODO - Pillow now supports ImageGrab on macOS.
from PIL import ImageGrab
_PILLOW_UNAVAILABLE = False
except ImportError:
# We ignore this because failures due to Pillow not being installed
# should only happen when the functions that specifically depend on
# Pillow are called. The main use case is when PyAutoGUI imports
# PyScreeze, but Pillow isn't installed because the user is running
# some platform/version of Python that Pillow doesn't support, then
# importing PyAutoGUI should not automatically fail because it
# imports PyScreeze.
# So we have a `pass` statement here since a failure to import
# Pillow shouldn't crash PyScreeze.
_PILLOW_UNAVAILABLE = True
def requiresPillow(wrappedFunction):
"""
A decorator that marks a function as requiring Pillow to be installed.
This raises PyScreezeException if Pillow wasn't imported.
"""
@functools.wraps(wrappedFunction)
def wrapper(*args, **kwargs):
if _PILLOW_UNAVAILABLE:
raise PyScreezeException('The Pillow package is required to use this function.')
return wrappedFunction(*args, **kwargs)
return wrapper
如果我尝试只输入'from PIL import Image‘,它会给出这个错误
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Edu 2019.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\offic\PycharmProjects\test\venv\Lib\site-packages\PIL\Image.py", line 93, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (C:\Users\offic\PycharmProjects\test\venv\Lib\site-packages\PIL\__init__.py)
这就是我安装枕头的时候
C:\Users\offic>py -m pip install --user Pillow
Requirement already satisfied: Pillow in c:\users\offic\pycharmprojects\test\venv\lib\site-packages (7.1.1)
这是pillow在我的包目录中的样子
pyscreeze表示,他们应该对安装Pillow感到满意
C:\Users\offic>py -m pip install --user pyscreeze
Requirement already satisfied: pyscreeze in c:\users\offic\pycharmprojects\test\venv\lib\site-packages (0.1.26)
Requirement already satisfied: Pillow>=5.2.0 in c:\users\offic\pycharmprojects\test\venv\lib\site-packages (from pyscreeze) (7.1.1)
我不知道发生了什么,因为我之前几乎没有安装包的问题,它似乎在正确的位置和最新的。请帮帮我!
发布于 2020-06-19 15:32:35
尽管上下文证据具有误导性,但您要寻找的是cv2库,而不是严格意义上的PIL。
因此,安装cv2,例如使用pip:
pip install opencv-python
然后在Python脚本中导入它:
import cv2
然后运行它。
发布于 2021-07-26 10:37:24
即使我也犯了同样的错误,以下是对我有效的方法:
python3 -m pip安装--升级pip python3 -m pip安装--升级枕头
我在Pillow包的官方文档中找到了这个
发布于 2022-02-05 09:08:31
我使用的是windows,这个方法对我很有效。
pip安装--升级pip
pip安装--升级Pillow
https://stackoverflow.com/questions/61463086
复制相似问题