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

Windows下Python3.12.4虚拟环境安装mmaction遇Pillow编译错误求助

问题描述

在Windows系统的Python3.12.4版本虚拟环境(venv)中安装mmaction模块时,始终出现Pillow编译依赖zlib缺失的错误,具体报错如下:

RequiredDependencyException: zlib

During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "C:\Users\babic\AppData\Local\Temp\pip-install-w9fq41js\pillow_fa46dd3e9ace49e494ddbe12da2bf332\setup.py", line 903, in <module>
      raise RequiredDependencyException(msg)
  RequiredDependencyException:

  The headers or library files could not be found for zlib,
  a required dependency when compiling Pillow from source.

  Please see the install instructions at:
     https://pillow.readthedocs.io/en/latest/installation.html


  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for Pillow
Running setup.py clean for Pillow
Failed to build Pillow
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (Pillow)

已尝试以下命令但未解决问题:

pip install mmaction
pip install --upgrade pip
pip install --upgrade Pillow
python -m pip install --upgrade pip
python -m pip install --upgrade pillow
python -m pip install --upgrade pip setuptools wheel
pip install Pillow  # was installed successfully
解决方法
  • 直接安装预编译的Pillow wheel包
    跳过源码编译步骤,强制使用适配Windows和Python3.12的预编译版本,执行命令:

    pip install pillow --only-binary :all:
    

    也可以指定兼容的具体版本(比如10.3.0):

    pip install pillow==10.3.0 --only-binary :all:
    

    安装完成后再尝试安装mmaction。

  • 手动配置zlib依赖

    1. 下载适配Windows系统的zlib开发包(需包含头文件和库文件),解压后找到include和lib目录;
    2. 添加系统环境变量:
      • 新建INCLUDE变量,将zlib的include路径加入;
      • 新建LIB变量,将zlib的lib路径加入;
    3. 重启命令行窗口,激活虚拟环境后重新安装mmaction。
  • 切换到conda环境管理依赖
    若venv环境下依赖问题难以排查,可尝试用conda创建环境:

    # 创建新环境
    conda create -n mmaction_env python=3.12.4
    # 激活环境
    conda activate mmaction_env
    # 安装conda维护的Pillow版本
    conda install pillow
    # 安装mmaction
    pip install mmaction
    
  • 重建虚拟环境
    删除现有虚拟环境,重新创建并初始化:

    # 删除旧虚拟环境(替换为你的环境路径)
    rm -r C:\path\to\your\venv
    # 新建虚拟环境
    python -m venv mmaction_venv
    # 激活环境
    mmaction_venv\Scripts\activate
    # 升级基础工具
    python -m pip install --upgrade pip setuptools wheel
    # 安装预编译Pillow
    pip install pillow --only-binary :all:
    # 安装mmaction
    pip install mmaction
    

内容的提问来源于stack exchange,提问作者marina05

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 13:25:56