Building wheels for collected packages: Pillow Building wheel for Pillow (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for Pillow (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [213 lines of output] <string>:42: RuntimeWarning: Pillow 7.0.0 does not support Python 3.12 and does not provide prebuilt Windows binaries. We do not recommend building from source on Windows. C:\Users\10237\AppData\Local\Temp\pip-build-env-r0_4ic4z\overlay\Lib\site-packages\setuptools\_distutils\dist.py:289: UserWarning: Unknown distribution option: 'tests_require' warnings.warn(msg) C:\Users\10237\AppData\Local\Temp\pip-build-env-r0_4ic4z\overlay\Lib\site-packages\setuptools\dist.py:760: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: Historical Permission Notice and Disclaimer (HPND) See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-312\PIL copying src\PIL\BdfFontFile.py -> build\lib.win-amd64-cpython-312\PIL copying src\PIL\BlpImagePlugin.py -> build\lib.win-amd64-cpython-312\PIL copying src\PIL\BmpImagePlugin.py -> build\lib.win-amd64-cpython-312\PIL copying src\PIL\BufrStubImagePlugin.py -> build\lib.win-amd64-cpython-312\PIL copying src\PIL\ContainerIO.py -> build\lib.win-amd64-cpython-312\PIL copying src\PIL\CurImagePlugin.py -> build\lib.win-amd64-cpython-312\PIL 翻译解释并提供解决
时间: 2025-03-22 19:06:09 浏览: 155
<think>嗯,用户遇到了在Windows上安装Pillow时因为Python 3.12不支持而导致构建wheel失败的问题。首先,我需要回想一下Pillow的安装依赖和常见的错误解决方法。根据之前的引用内容,像这种构建失败通常是因为缺少必要的库或者Python版本不兼容。
用户提到Python 3.12是最新版本,可能Pillow的官方wheel还没有适配这个版本,所以pip尝试从源码编译但失败了。这时候,解决方案可能需要用户手动安装依赖或者使用较旧的Python版本。引用[2]中提到在Linux下需要安装额外的库,但用户是在Windows上,可能需要类似的操作,比如安装Visual C++构建工具或者其他的编译依赖。
另外,引用[4]指出Python 3.12可能暂时无法构建某些库的wheel,比如aiohttp,类似的情况可能适用于Pillow。这时候降级Python到3.11可能是一个有效的方法,或者等待官方更新支持。
还有,检查用户是否安装了正确的构建工具,比如setuptools和wheel的最新版本,以及Microsoft Visual C++ Build Tools,这些在Windows上编译Python包时是必须的。引用[5]提到在安装后需要测试PIL的导入,可能需要用户确认安装是否成功。
总结下来,可能的解决步骤包括:安装编译依赖、使用预发布版本、降级Python版本、或者从第三方获取预编译的wheel。同时,用户可能需要更新pip和setuptools,确保环境配置正确。</think>### 逐步解决方案
#### 问题背景
在Windows系统上安装$Pillow$库时,由于Python 3.12尚未提供预编译的二进制包(wheel),导致从源码构建失败。错误可能表现为:
```
ERROR: Failed building wheel for Pillow
```
或
```
This error originates from a subprocess, and is likely not a problem with pip.
```
---
#### 解决步骤
1. **安装编译依赖**
- Pillow的构建依赖`zlib`、`libjpeg`等C库。在Windows上需通过以下工具支持编译:
- 安装**Microsoft Visual C++ Build Tools**(推荐使用Visual Studio 2019或更高版本)[^2]
- 确保勾选“C++桌面开发”组件
- 安装Python开发工具:
```bash
pip install setuptools wheel --upgrade
```
2. **尝试安装预发布版本**
- Pillow可能已发布适配Python 3.12的测试版:
```bash
pip install Pillow --pre
```
3. **降级Python版本**
- 若急需稳定环境,暂时使用Python 3.11(Pillow官方支持更完善):
- 从[Python官网](https://www.python.org/downloads/)下载3.11.x版本
- 创建虚拟环境:
```bash
python -m venv pillow_env
pillow_env\Scripts\activate
pip install Pillow
```
4. **从第三方获取预编译wheel**
- 访问[Unofficial Windows Binaries for Python](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow),下载对应Python 3.12的`.whl`文件:
```bash
pip install Pillow-9.5.0-cp312-cp312-win_amd64.whl
```
5. **验证安装**
- 测试Pillow是否正常工作:
```python
from PIL import Image
im = Image.new('RGB', (100, 100), (255, 0, 0))
im.show()
```
---
#### 失败排查
- 若仍报错`no prebuilt binaries`,检查:
- Python版本是否为`3.12.x`(通过`python --version`确认)
- 确保编译工具链(如`setuptools`≥60.0)已更新[^3]
- 查看完整错误日志,定位具体缺失的依赖项[^1]
---
阅读全文
相关推荐



















