pillow使用报错,安装低版本 9.5.0也报错error: subprocess-exited-with-error,module ‘PIL.Image‘ has no attribute

pillow使用报错,安装低版本 9.5.0也报错error: subprocess-exited-with-errorAttributeError: module ‘PIL.Image’ has no attribute ‘ANTIALIAS’。

 pip install --force-reinstall -v "Pillow==9.5.0"

Using pip 25.0.1 from /Users/frank/PycharmProjects/auto-login/.venv/lib/python3.13/site-packages/pip (python 3.13)
Collecting Pillow==9.5.0
Using cached Pillow-9.5.0.tar.gz (50.5 MB)
Running command pip subprocess to install build dependencies
Using pip 25.0.1 from /Users/frank/PycharmProjects/auto-login/.venv/lib/python3.13/site-packages/pip (python 3.13)
Collecting setuptools>=40.8.0
Obtaining dependency information for setuptools>=40.8.0 from https://files.pythonhosted.org/packages/54/21/f43f0a1fa8b06b32812e0975981f4677d28e0f3271601dc88ac5a5b83220/setuptools-78.1.0-py3-none-any.whl.metadata
Using cached setuptools-78.1.0-py3-none-any.whl.metadata (6.6 kB)
Using cached setuptools-78.1.0-py3-none-any.whl (1.3 MB)
Installing collected packages: setuptools
Successfully installed setuptools-78.1.0
Installing build dependencies … done
Running command Getting requirements to build wheel
Traceback (most recent call last):
File “/Users/frank/PycharmProjects/auto-login/.venv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 389, in
main()
~~~~^^
File “/Users/frank/PycharmProjects/auto-login/.venv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 373, in main
json_out[“return_val”] = hook(**hook_input[“kwargs”])
~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/frank/PycharmProjects/auto-login/.venv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 143, in get_requires_for_build_wheel
return hook(config_settings)
File “/private/var/folders/wt/xvxk7p4j41n_c8x828mp0cz00000gn/T/pip-build-env-2fvk2mol/overlay/lib/python3.13/site-packages/setuptools/build_meta.py”, line 334, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/private/var/folders/wt/xvxk7p4j41n_c8x828mp0cz00000gn/T/pip-build-env-2fvk2mol/overlay/lib/python3.13/site-packages/setuptools/build_meta.py”, line 304, in _get_build_requires
self.run_setup()
~~~~~~~~~~~~~~^^
File “/private/var/folders/wt/xvxk7p4j41n_c8x828mp0cz00000gn/T/pip-build-env-2fvk2mol/overlay/lib/python3.13/site-packages/setuptools/build_meta.py”, line 522, in run_setup
super().run_setup(setup_script=setup_script)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/private/var/folders/wt/xvxk7p4j41n_c8x828mp0cz00000gn/T/pip-build-env-2fvk2mol/overlay/lib/python3.13/site-packages/setuptools/build_meta.py”, line 320, in run_setup
exec(code, locals())
~~~~^^^^^^^^^^^^^^^^
File “”, line 29, in
File “”, line 26, in get_version
KeyError: ‘version
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
full command: /Users/frank/PycharmProjects/auto-login/.venv/bin/python /Users/frank/PycharmProjects/auto-login/.venv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py get_requires_for_build_wheel /var/folders/wt/xvxk7p4j41n_c8x828mp0cz00000gn/T/tmp1r8v33f3
cwd: /private/var/folders/wt/xvxk7p4j41n_c8x828mp0cz00000gn/T/pip-install-28xm4bwr/pillow_601c554f33ee4516a144f33ae8a3197e
Getting requirements to build wheel … error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.


在使用ddddocr进行图片识别时,报错了:

AttributeError: module ‘PIL.Image’ has no attribute ‘ANTIALIAS’

我使用的是Python 3.13,查看一下pillow的版本:

print(PIL.__version__)
 
10.0.0

在pillow的release notes中找到了问题:

在pillow的10.0.0版本中,ANTIALIAS方法被删除了,使用新的方法即可:

Image.LANCZOS
 
Image.Resampling.LANCZOS

解决办法:(推荐方案二)

方案一,修改ddddocr的_init_.py文件,将其中的ANTIALIAS替换为新方法:

# image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.ANTIALIAS).convert('L')
image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.LANCZOS).convert('L')

方案二,降级Pillow的版本,比如使用9.5.0版本

https://pypi.org/project/pillow/9.5.0/

先卸载,再重新安装

pip uninstall -y Pillow
pip install Pillow==9.5.0 

macos 安装失败:

1、安装packaging

python3 -m pip install packaging

2、找出适应名称,记住第一行

python3 -c"from packaging import tags; print('\n'.join([str(t) for t in tags.sys_tags()]))" |head -5
 frank@FRANKCYANG-MB0 auto-login % python3 -c"from packaging import tags; print('\n'.join([str(t) for t in tags.sys_tags()]))" |head -5
cp313-cp313-macosx_14_0_arm64
cp313-cp313-macosx_14_0_universal2
cp313-cp313-macosx_13_0_arm64
cp313-cp313-macosx_13_0_universal2
cp313-cp313-macosx_12_0_arm64
(.venv) frank@FRANKCYANG-MB0 auto-login % 

3、修改名称并安装

在这里下载Pillow安装包https://pypi.org/project/Pillow/8.0.1/#files

3.1 重命名Pillow-8.0.1-(刚刚输出的第一行内容).whl

mv Pillow-8.0.1-cp38-cp38-macosx_11_0_x86_64.whl Pillow-8.0.1-cp38-cp38-macosx_11_0_universal2.whl

3.2 安装

python3 -m pip install /Users/mimi/Downloads/Pillow-8.0.1-cp39-cp39-macosx_12_0_x86_64.whl 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码讲故事

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值