Sygil-Dev / stable-diffusion

GNU Affero General Public License v3.0
1.72k stars 149 forks source link

Linux installation script issues (Module named 'frontend' not found) #129

Closed MeesCode closed 2 years ago

MeesCode commented 2 years ago

Just followed the Linux installation guide and got this issue in step 8

Traceback (most recent call last):
  File "scripts/webui.py", line 3, in <module>
    from frontend.frontend import draw_gradio_ui
ModuleNotFoundError: No module named 'frontend'
Relauncher: Process is ending. Relaunching in 0.5s...
hlky commented 2 years ago

It looks like it hasn't updated for some reason, there must be an issue with the linux installation script.

@JoshuaKimsey made the guide and linux installation script, you'll have to wait for him to have a look, I haven't tried the linux instructions myself because I use windows

My suggestion would be try git pull to get the updates

stestagg commented 2 years ago

This error typically happens when Python can't find the stable-diffusion code to import. it may be worth trying: env PYTHONPATH=. ./linux-sd.sh

This will make python look in the 'current directory' for imports, and then it will find the frontend directory. The various helper/wrapper scripts end up trying to run the UI server from the correct directory.

I haven't tried it myself, as I run the server slighly differently, but this should work

FyorDev commented 2 years ago

Same issue here, it seems many other modules in webui.py aren't found either, "frontend" being the first. (gradio, k_diffusion, pynvml, torch, einops, omegaconf, ldm, transformers, gfpgan, basicr, realesrgan).

Haven't had any luck with the env PYTHONPATH= command @stestagg suggested.

Probably a very simple problem but I hope it gets resolved soon since I don't know how to fix this either :)

hlky commented 2 years ago

@FyorUU sounds like the environment isn't being created or something.

You could try docker if you need the installation to be as automatic as possible

yourjelly commented 2 years ago

I had this issue getting my docker running. The problem had to do with folder permissions when installing conda, so it wasn't doing it at all.

CONDA_DIR /opt/conda
wget -O ~/miniconda.sh -q --show-progress --progress=bar:force https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
    /bin/bash ~/miniconda.sh -u -b -p $CONDA_DIR && \
    rm ~/miniconda.sh
PATH=$CONDA_DIR/bin:$PATH
conda update -n base -c defaults conda

This fixed it for me. Although I wasn't going to recommend edits because I think it's due to an Unraid quirk

FyorDev commented 2 years ago

Fixed it! I had 2 major problems.

@hlky The problem indeed seemed to be with the environment. I'm also using the Linux install script which requires you to manage Anaconda/Miniconda yourself beforehand, but it didn't work with miniconda3 and only worked when I eventually installed the regular anaconda3. Both could run 'conda env' which the guide states as a requirement.

Finding frontend/frontend.py was my first issue which @MeesCode also had, I solved this with setting PYTHONPATH=. in the ultimate-stable-diffusion directory (thanks @stestagg). I don't know if this has to be done with the environment active but did it in the lsd env.

Then frontend.py in the frontend folder could be found now, but all the other modules which conda should have taken care of couldn't be found. I've removed miniconda3 and installed anaconda3, then reinstalled the script, which appears to have completely solved the issue. Happily generating images with the browser gui now.

So in conclusion: the Linux install script might only work with anaconda3 and the PYTHONPATH needs to be corrected.

skorokithakis commented 2 years ago

This fails in docker-compose up as well.

dogarrowtype commented 2 years ago

I fixed this with a simple pip3 install -e . in the stable-diffusion folder after a commit a day or so ago caused this bug.

JoshuaKimsey commented 2 years ago

Both could run 'conda env' which the guide states as a requirement.

@FyorUU @hlky Wait, does miniconda3 use different commands compared to the regular Anaconda? I thought both used the same conda env commands to manage environments? I may need to investigate this further... I never needed to mess with the PYTHONPATH either, so it may be it's an issue between Anaconda and Miniconda. I'll look into this and respond shortly.

skorokithakis commented 2 years ago

@dogarrowtype that didn't work for me in Docker, sadly.

FyorDev commented 2 years ago

@JoshuaKimsey They do both feature the 'conda env' command at the very least, and your Linux install script also seemed to display the same things either way from what I remember seeing (such as successfully installing all the environment.yaml modules). Miniconda3 didn't seem to have any problems in the installer script at all until it is time to run the relauncher.py, which will keep failing due to not finding the correct modules.

It could still be a user error on my part, all I know for sure is that I have repeatedly failed running the installer with miniconda3 trying all kind of things and was finally successful after switching to anaconda3. I hope you can recreate and fix the issue, good luck and thank you for your work Joshua and hlky.

yourjelly commented 2 years ago

@dogarrowtype that didn't work for me in Docker, sadly.

Also try on line 25 of entrypoint.sh 25:PIP_EXISTS_ACTION=w

JoshuaKimsey commented 2 years ago

@FyorUU I just uninstalled Anaconda3 and installed Miniconda3 and it still worked as expected. So I'm really not sure what is causing the issue that you encountered. I think probably the best solution is what you did, which is uninstall Miniconda and install Anaconda. It could be an edge case thing between how the two install for some people. I really need to try and figure out if there is a way to test for an install of Anaconda and just do it for the user.

I did discover a small issue while testing this though. It seems the environment.yaml may not be updating correctly when I pull new updates down from GitHub, so I'll need to look into that. That should have no effect on the initial run of the script installing it though, which means no effect on the Anaconda vs Miniconda thing.

trufty commented 2 years ago

Try this at the top of webui.py

import sys
sys.path.append('.')

edit: This fixed it for me in my custom docker container

JoshuaKimsey commented 2 years ago

@MeesCode Hey sorry I just realized I had replied back to you directly. I'm not sure why this would be throwing that error. It is possible it's a problem with my script, but the first main thing is to make sure that you have the latest updates from the repo, the latest version of my script, and that Anaconda is setup correctly. I tested Miniconda and it worked fine for me as well, however others here, such as @FyorUU, seemed to have issues getting it to function correctly with it.

If you would like to try the full-fledged version of Anaconda first, then you can uninstall miniconda (it's the same instructions for Anaconda and Miniconda, just change the folder name in step 2, as well as remove the conda path in your .bash_profile/.bashrc file), then you can install the full-fledged Anaconda and try that out instead. The instructions should tell you how to do it for your system type.

Let me know if you have anymore issues with this, and I'll see how I can help.

hlky commented 2 years ago

Closing this as it seems to be resolved for those involved, if anyone else has a problem they can create another issue.

rolo commented 2 years ago

I managed to fix this after having the same issue with the missing "frontend" module after running the linux installer (Ubuntu 22.04) by simply activating the env after the script finished running.

It looked to me as though it was trying to run without using the new conda env so not finding any of the dependencies.

So after the script had failed I activated the conda env with:

conda activate lsd

I was then able to launch from the ultimate-stable-diffusion dir with:

python scripts/webui.py

I'm using miniconda rather than full anaconda. I installed it following the instructions in the official Stable Diffusion repo the other day, I haven't used any anaconda version prior to this so am not best placed to try and fix the installed script if this is the issue, but maybe this will help someone else. Cheers.

JoshuaKimsey commented 2 years ago

@rolo Yeah, Miniconda seems to be an issue for some people. I'm not completely sure why, but my only suggestion is to uninstall Miniconda and install the full version of Anaconda instead. I left instructions and links for that in my last post above here. Try that and see if it works correct;y. Also, make sure you have the newest version of the script installed too.

rolo commented 2 years ago

@rolo Yeah, Miniconda seems to be an issue for some people. I'm not completely sure why, but my only suggestion is to uninstall Miniconda and install the full version of Anaconda instead. I left instructions and links for that in my last post above here. Try that and see if it works correct;y. Also, make sure you have the newest version of the script installed too.

Ah sorry I wasn't clear - I was letting folks know I got it running fine with miniconda I just needed to activate the env afterwards. I've edited my post.

rbracco commented 2 years ago

Same issue here, it seems many other modules in webui.py aren't found either, "frontend" being the first. (gradio, k_diffusion, pynvml, torch, einops, omegaconf, ldm, transformers, gfpgan, basicr, realesrgan).

Haven't had any luck with the env PYTHONPATH= command @stestagg suggested.

Probably a very simple problem but I hope it gets resolved soon since I don't know how to fix this either :)

I'm experiencing the same, it's like the script doesn't install any of the libraries and they have to be added one by one.

JoshuaKimsey commented 2 years ago

@rbracco Are you using Anaconda or Miniconda?

rbracco commented 2 years ago

I tried with Miniconda, uninstalled and cleared everything from my .bashrc and started over with Anaconda.

Ubuntu 20.04, installed Anaconda3-2022.05-Linux-x86_64.sh

yourjelly commented 2 years ago

This is weird because the docker runs on Linux and works with miniconda

On Fri, Sep 2, 2022, 11:17 PM Robert Bracco @.***> wrote:

I tried with Miniconda, uninstalled and cleared everything from my .bashrc and started over with Anaconda.

Ubuntu 20.04, installed Anaconda3-2022.05-Linux-x86_64.sh

— Reply to this email directly, view it on GitHub https://github.com/hlky/stable-diffusion/issues/129#issuecomment-1236036210, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGIX76JWVLESGJRF7MQI74TV4K7MTANCNFSM6AAAAAAQALVU44 . You are receiving this because you commented.Message ID: @.***>

rbracco commented 2 years ago

I just now got it working after around an hour of fiddling but it required lots of small manual installs into the environment including stuff like updating some subdependencies (e.g. websockets 9.1->10.3) to get around errors. I also had to manually execute the WGET for the GFPGAN and RealESRGAN, and I still have the warning LDSR not found at path, please make sure you have cloned the LDSR repo to ./src/latent-diffusion/ but it is at least generating images.

Edit: to be clear I'm precisely following the install guide here: https://github.com/hlky/stable-diffusion/wiki/Linux-Installation

JoshuaKimsey commented 2 years ago

@rbracco Geez... I'm not sure what's going on. Did it start working after switching to Anaconda? Also, what did the terminal say when my script got to the point of downloading the models? Because that should be a simple operation on it's own? I'm trying to figure out what's going wrong for some people, cause most of what I use is basic Bash stuff, save for the environment stuff using Conda.

rbracco commented 2 years ago

Here's a long post with the process I followed, hope it helps you to debug. Thanks for your work.

Output on the normal script looked totally successful: image

Then after asking if I wanted to run in standard/optimized mode (I chose optimized and have > 6gb ram) I got the gradio not installed error image

I noticed at that point lsd wasn't activated either so I killed the process, ran conda activate lsd, gradio still wasnt installed, so I pip installed it. Next none of the editable install models like k-diffusion were installed so I ran

pip install -e git+https://github.com/hlky/facexlib#egg=facexlib &&
pip install -e git+https://github.com/CompVis/taming-transformers#egg=taming-transformers &&
pip install -e git+https://github.com/openai/CLIP#egg=clip &&
pip install -e git+https://github.com/TencentARC/GFPGAN#egg=GFPGAN &&
pip install -e git+https://github.com/xinntao/Real-ESRGAN#egg=realesrgan &&
pip install -e git+https://github.com/hlky/k-diffusion-sd#egg=k_diffusion

Next, no pynvml installed, so I ran pip install pynvml==11.4.1 (following the environment.yaml version numbers).

Next block of errors was

  1. GFPGAN model not found at path
  2. RealERSGAN not found at path
  3. package not found error filelock

image

Fixes: 1 and 2. Manually call the various WGETs from the bash script wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P ./src/realesrgan/experiments/pretrained_models

  1. pip install filelock

The final error was __init__() got an unexpected keyword argument 'logger' from websockets which I fixed with pip install -u websockets to go from 9.1->10.3

Finally I was able to run stuff but with a fair amount of bugs such as:

  1. Program crashes if input is empty or longer than 75 characters
  2. ImageLab lets me load an input image, but the output image never appears, it just says "loading"
  3. Clicking "mask" on img2img Image Editor Mode causes the program to freeze and need to be rebooted.
  4. Occasional CUDA out of memory errors.