You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

64位系统venv中安装Pillow失败(zlib依赖缺失)求助

解决Pillow安装时zlib依赖缺失的问题

问题描述

在64位系统的Python虚拟环境(venv)中执行pip install Pillow时安装失败,编译Pillow源码时提示找不到zlib头文件或库文件。尝试通过MSYS2安装zlib后再次安装,问题依旧。关键报错如下:

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
  ╰─> [199 lines of output]
      ...
      running build_ext
     
     
      The headers or library files could not be found for zlib,
      a required dependency when compiling Pillow from source.
     
      ...
      __main__.RequiredDependencyException: zlib
     
      ...
      __main__.RequiredDependencyException:
     
      The headers or library files could not be found for zlib,
      a required dependency when compiling Pillow from source.
     
     
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for Pillow
Failed to build Pillow
ERROR: Could not build wheels for Pillow, which is required to install pyproject.toml-based projects

解决方案

方案1:直接安装预编译的Pillow包(推荐)

跳过源码编译流程,强制pip使用适配系统的预编译wheel文件,执行命令:

pip install --only-binary :all: Pillow

方案2:正确配置MSYS2环境后编译安装

若必须从源码编译,需确保编译环境能识别MSYS2安装的zlib:

  1. 打开MSYS2 MinGW 64-bit终端(需与系统位数匹配)
  2. 安装zlib开发包:
    pacman -S mingw-w64-x86_64-zlib
    
  3. 在该终端中激活你的Python虚拟环境:
    # 替换为你的venv激活脚本路径
    source /path/to/your/venv/Scripts/activate
    
  4. 执行Pillow安装命令:
    pip install Pillow
    

原因说明:之前失败是因为普通Windows终端(cmd/PowerShell)中,MSYS2安装的zlib路径未被加入编译环境的搜索列表,导致Pillow编译脚本无法定位依赖。在MSYS2终端操作会自动配置正确的环境变量。

内容的提问来源于stack exchange,提问作者Илиян Гълъбов

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:29:52