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

VQGAN+CLIP加载库触发ImportError报错,求分步解决方案

解决VQGAN+CLIP加载库时的PIL ImportError问题

报错信息

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-c026441db553> in <cell line: 13>()
     11 from omegaconf import OmegaConf
     12 from PIL import Image
---> 13 from taming.models import cond_transformer, vqgan
     14 import torch
     15 from torch import nn, optim

7 frames
/usr/local/lib/python3.10/dist-packages/PIL/ImageFont.py in <module>
     32 
     33 from . import Image
---> 34 from ._util import isDirectory, isPath
     35 
     36 LAYOUT_BASIC = 0

ImportError: cannot import name 'isDirectory' from 'PIL._util' (/usr/local/lib/python3.10/dist-packages/PIL/_util.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

分步解决方法

  • 第一步:在Colab新建一个单元格,运行以下命令卸载当前版本的Pillow:
    !pip uninstall -y pillow
    
  • 第二步:安装兼容的旧版本Pillow(9.5.0版本可适配VQGAN+CLIP的依赖需求):
    !pip install pillow==9.5.0
    
  • 第三步:重启Colab运行时:点击页面顶部「Runtime」菜单 → 选择「Restart runtime」
  • 第四步:重新运行「Loading libraries and definitions」单元格

问题原因

最新版本的Pillow(Python图像处理库)移除了VQGAN+CLIP代码依赖的isDirectory方法,安装指定旧版本即可匹配代码的依赖要求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 16:32:47