CompVis / taming-transformers

Taming Transformers for High-Resolution Image Synthesis
https://arxiv.org/abs/2012.09841
MIT License
5.83k stars 1.15k forks source link

ModuleNotFoundError: no module named "taming" #176

Open Nughu opened 2 years ago

Nughu commented 2 years ago

I get this error when executing stable diffusion: IMG_20220902_010908.jpg

rabidcopy commented 2 years ago

I've also experienced this issue even though taming-transformers is installed and had been working fine. Doesn't matter if I git clone this repository and install it that way or just pip install taming-transformers. However if I install taming-transformers-rom1504 everything is working fine again. I'm not sure what happened as taming-transformers hasn't appeared to have received any updates.

vanakema commented 2 years ago

You probably need to add -e to your pip install. Sometimes if you've done some commands with your package manager, it will wipe the -e from the requirements.txt. At least adding the -e back to the beginning of the git+ line for taming-transformers fixed it for me yesterday

rabidcopy commented 2 years ago

After uninstalling and reinstalling with pip install -e and running pip install -e . in stable-diffusion it seems to be back to normal again. Odd.

chavinlo commented 2 years ago

This is not the correct thing to do when this happens btw. For me pip install -e . didnt worked many times Copy the taming folder from this repo (CompVis/taming-transformers) to the folder where you are executing from (from what I can see, its /dockerx/rocm/stable-diffusion) In your case:

cd /dockerx/rocm/
git clone https://github.com/CompVis/taming-transformers
cd stable-diffusion
cp -dr ../taming-transformers/taming/ ./taming
vanakema commented 2 years ago

This is not the correct thing to do when this happens btw.

For me pip install -e . didnt worked many times

Copy the taming folder from this repo (CompVis/taming-transformers) to the folder where you are executing from (from what I can see, its /dockerx/rocm/stable-diffusion)

In your case:


cd /dockerx/rocm/

git clone https://github.com/CompVis/taming-transformers

cd stable-diffusion

cp -dr ../taming-transformers/taming/ ./taming

While that does work, I would not do that. Manually cloning a repo of a dependency you're using and copying the contents of a folder within it into the folder you're trying to us is definitely not the best practice here.

If you pip install using pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers like it is listed in the environment.yaml, it should end up in a folder <stable_diffusion_root>/src. If you're not using conda, which does some magic to your PYTHONPATH env var, you can fix this by running export PYTHONPATH= <stable_diffusion_root>/src:$PYTHONPATH

If you add ENV PYTHONPATH= <stable_diffusion_root>/src/taming-transformers to your Dockerfile, you should be good to go for taming if that's the only dependency you had issues with. I had issues with CLIP, and some of the local repo modules as well so personally my Dockerfile has the following

PYTHONPATH= <stable_diffusion_root>:<stable_diffusion_root>/src: <stable_diffusion_root>/src/taming-transformers

Conda automatically adds your current directory into your PYTHONPATH so for a python docker container we have to do this ourselves.

Something about the way they structured the taming repo doesn't register in pythons module loaders at the repos root. You have to go 1 deeper. CLIP seems to have done it right (and if you install without the -e for clip, you don't need to set any PYTHONPATH entry for it in my experience)

Having to set a PYTHONPATH certainly isn't an ideal solution, but it's def a more portable solution for using these repos that have changed since their last PyPi publishing with changes that have messed something up with modules, or don't conform to the current PEP spec

chris-morgan commented 2 years ago

The real problem here is that this package has not been coded correctly to be a dependency; in setup.py, find_packages returns an empty list. The simplest fix is to create empty __init__.py files in taming/ and all its subdirectories that should be included as part of the distribution—that satisfies find_packages. Then the -e workaround could be dropped.

chris-morgan commented 2 years ago

(Actually, see #173 which does a more thorough job of this.)

flying-sheep commented 2 years ago

can you please merge that one? as is, this repository is impossible to use with standard tools.

flying-sheep commented 2 years ago

Also I encourage everyone who makes packages to stop using setup.py and read the python packaging tutorial.