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
相关产品推荐
相关产品推荐

