stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

No module named 'taming'

Open BPplays opened this issue 3 years ago • 6 comments

I'm getting this error when using Optimized Stable Diffusion but NOT Stable Diffusion:

Traceback (most recent call last): File "D:\Programs\Optimized Stable Diffusion\optimizedSD\optimized_txt2img.py", line 198, in model = instantiate_from_config(config.modelUNet) File "d:\programs\stable diffusion\ldm\util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(**config.get("params", dict())) File "d:\programs\stable diffusion\ldm\util.py", line 93, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "C:\My Files\Programs\Python\Python39\lib\importlib_init_.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "d:\programs\stable diffusion\optimizedSD\ddpm.py", line 14, in from ldm.models.autoencoder import VQModelInterface File "d:\programs\stable diffusion\ldm\models\autoencoder.py", line 6, in from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer ModuleNotFoundError: No module named 'taming'

BPplays avatar Aug 23 '22 15:08 BPplays

You need to install the taming-transformers package from the repo

pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers

aravind598 avatar Aug 23 '22 16:08 aravind598

You need to install the taming-transformers package from the repo

pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers

I would add, for modules that appear in the repository directory but still return the ModuleNotFoundError, the solution would be to add the following directly after the "import sys" or "import argparse, os, sys, glob, random" line:

sys.path.append('.')

May also be valuable if you don't wish to install the Git repo as a global.

GucciFlipFlops1917 avatar Aug 23 '22 17:08 GucciFlipFlops1917

it's still not working I'm getting the slightly different error:

Traceback (most recent call last): File "D:\Programs\Optimized Stable Diffusion\optimizedSD\optimized_txt2img.py", line 199, in model = instantiate_from_config(config.modelUNet) File "d:\programs\stable diffusion\ldm\util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(**config.get("params", dict())) File "d:\programs\stable diffusion\ldm\util.py", line 93, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "C:\My Files\Programs\Python\Python39\lib\importlib_init_.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "d:\programs\stable diffusion\optimizedSD\ddpm.py", line 14, in from ldm.models.autoencoder import VQModelInterface File "d:\programs\stable diffusion\ldm\models\autoencoder.py", line 6, in from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer ModuleNotFoundError: No module named 'taming'

BPplays avatar Aug 23 '22 19:08 BPplays

Try my method. Download the taming-transformers repository and place the "taming" folder in your Stable-Diffusion directory. Afterwards, add sys.path.append('.') right after line 1 and try running the model.

GucciFlipFlops1917 avatar Aug 23 '22 21:08 GucciFlipFlops1917

Don't know if this helps, but installing with pip3 on Ubuntu (without conda) had this error.. the sys.path.error helps find ldm, but I had to use export PYTHONPATH="${PYTHONPATH}:/path/to/your/project/" and resinstall making sure I used the -e in the below command. (not sure which resolved). Onto the next error "OSError: We couldn't connect to 'https://huggingface.co' " ; ). Thanks again so much for this repo!

pip3 install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers

auwsom avatar Aug 24 '22 01:08 auwsom

had the same problem and found a solution in telegram: cd stable-diffusion conda env remove -n ldm conda env create -f environment.yaml conda activate ldm

thezveroboy avatar Aug 27 '22 09:08 thezveroboy