from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer ModuleNotFoundError: No module named 'taming'
在安装 taming-transformers时,出现了以下两个报错:
报错一:
from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer
ModuleNotFoundError: No module named 'taming'
报错二:
from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer
ImportError: cannot import name 'VectorQuantizer2' from 'taming.modules.vqvae.quantize' (/home/usr/anaconda3/envs/xxx/lib/python3.8/site-packages/taming_transformers-0.0.1-py3.8.egg/taming/modules/vqvae/quantize.py)
首先来看第一个报错:
个人尝试了以下前三种方案均无法解决,第四种方案会出现第二个错误:
(1)pip install taming-transformers 安装 不报错但是运行提示包不存在
(2)git clone https://github.com/CompVis/taming-transformers.git
pip install -e /path/to/taming-transformers
(3) 从pypi页taming-transformers · PyPI下载whl文件
pip install path/to/taming_transformers-0.0.1-py3-none-any.whl
(4)下载pypi页的压缩文件解压后安装
wget https://files.pythonhosted.org/packages/03/ba/b22d13b38dee3805982a3ee2ef03234f11b6f26aa6220c92b23a0fc760a3/taming-transformers-0.0.1.tar.gz
tar -zxvf taming-transformers-0.0.1.tar.gz
cd taming-transformers-0.0.1
python setup.py install
安装完成后变为了报错二:
ImportError: cannot import name 'VectorQuantizer2' from 'taming.modules.vqvae.quantize'
查看 quantize.py 里边值确实没有实现 VectorQuantizer2, 于是将 autoencoder.py中
# from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer
改为:
from taming.modules.vqvae.quantize import VectorQuantizer as VectorQuantizer
报错成功解决。