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 
### 虚拟环境中的 OpenCV 安装错误解决方案 当在虚拟环境中安装 OpenCV 并遇到 `subprocess-exited-with-error` 或者类似的错误时,通常是因为依赖项未正确配置或者编译过程中缺少必要的库文件。以下是针对该问题的分析和解决方法: #### 错误原因分析 上述错误表明,在尝试显示图像时,传递给 `imshow` 函数的对象为空或尺寸不合法[^1]。这可能由以下几个因素引起: - 图像加载失败,可能是路径错误或文件损坏。 - 编译 OpenCV 时缺少某些必要组件,例如 GUI 支持模块。 - Python 的虚拟环境中未正确链接到系统的共享库。 --- #### 解决方案 ##### 方法一:验证图像加载过程 确保用于测试的图片能够被成功读取并具有有效维度。可以使用以下代码片段来检查图像是否正常加载: ```python import cv2 image_path = "path_to_your_image.jpg" image = cv2.imread(image_path) if image is None: print(f"Error: Unable to load the image from {image_path}. Please check the path and file format.") else: print(f"Image loaded successfully with dimensions: {image.shape}") ``` 如果此脚本报告无法加载图像,则需确认输入路径以及文件是否存在且格式支持。 ##### 方法二:重新构建带有完整功能集的 OpenCV 对于 ROS 和其他复杂框架集成的情况,建议手动编译最新版本的 OpenCV 来满足特定需求。具体操作如下所示: 1. **更新系统包管理器** 确保开发工具链是最新的,并安装所有必需的依赖关系。 ```bash sudo apt update && sudo apt upgrade -y sudo apt install build-essential cmake git pkg-config libgtk-3-dev \ libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \ gfortran openexr libatlas-base-dev python3-dev python3-numpy \ libtbb2 libtbb-dev libdc1394-22-dev ``` 2. **下载源码并设置 CMake 参数** 下载目标版本的 OpenCV 源代码并通过自定义选项启用所需特性。 ```bash cd ~/ git clone https://github.com/opencv/opencv.git cd opencv mkdir build && cd build cmake -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_TBB=ON \ -D BUILD_opencv_python3=ON .. make -j$(nproc) sudo make install sudo ldconfig ``` 完成以上步骤后重启终端窗口以应用更改。 ##### 方法三:调整 VirtualEnv 配置 有时即使全局范围内存在适当版本的 OpenCV ,Python 中创建的新隔离空间仍会忽略这些资源。因此需要显式指定要使用的解释程序及其关联扩展名。 执行下面命令建立兼容新软件栈的工作区: ```bash virtualenv --system-site-packages venv_name source ./venv_name/bin/activate pip install numpy scipy matplotlib pillow seaborn scikit-image imutils tensorflow keras h5py pandas jupyterlab ipython ``` 注意这里加入了参数 `--system-site-packages` 允许访问主机上的公共数据集合而不是完全封闭起来单独处理每一个请求。 最后再次试验先前引发异常的应用场景看问题是否已经得到修复。 --- ### 总结 通过仔细排查基础素材获取环节、优化本地化部署流程以及合理规划沙盒边界条件等方式可有效缓解乃至彻底消除此类技术难题带来的困扰。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

代码讲故事

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

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

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

打赏作者

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

抵扣说明:

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

余额充值