FahimF / sd-gui

Clean and simple Stable Diffusion GUI for macOS, Windows, and Linux
MIT License
230 stars 17 forks source link

No module named 'torch' #5

Closed gimmel closed 1 year ago

gimmel commented 1 year ago

Installation ran without errors, but I can’t start gui.py because of a missing module.

Traceback (most recent call last): File "/Users/mkaiser/sd-gui/gui.py", line 2, in import torch ModuleNotFoundError: No module named 'torch'

I already installed pytorch-nightly but it did not help.

HugoSega commented 1 year ago

Installation ran without errors, but I can’t start gui.py because of a missing module.

Traceback (most recent call last): File "/Users/mkaiser/sd-gui/gui.py", line 2, in import torch ModuleNotFoundError: No module named 'torch'

I already installed pytorch-nightly but it did not help.

pip install diffusers --force-reinstall --no-cache-dir

gimmel commented 1 year ago

I tried this already, but it does not help. There is still the same error: ModuleNotFoundError: No module named 'torch'

HugoSega commented 1 year ago

Make sure conda ml is activated

conda activate ml cd sd-gui python gui.py

gimmel commented 1 year ago

conda info --env doesn't show a ml environment. So there must be a problem in the beginning of the installation. I deleted everything and started over.

~ % /bin/bash -c "$(curl -fsSL https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh)"
Please run using "bash" or "sh", but not "." or "source"\n/bin/bash: line 11: return: can only `return' from a function or sourced script

But I can start the installation, which ends in

WARNING: md5sum mismatch of tar archive
expected: 41abe40ea68b8cba7668f9d0110eab4f
     got: 0961cd918a612915577461e6ac5696f9
Unpacking payload ...
/bin/bash: line 409: /Users/mkaiser/miniconda3/conda.exe: cannot execute binary file
/bin/bash: line 411: /Users/mkaiser/miniconda3/conda.exe: cannot execute binary file

So I downloaded https://docs.conda.io/en/latest/miniconda.html https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh and installed it manually, which worked without errors.

Then I tried to create them environment: conda create -n ml python=3.8.8 which results in

Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - python=3.8.8

Current channels:

  - https://repo.anaconda.com/pkgs/main/osx-arm64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/osx-arm64
  - https://repo.anaconda.com/pkgs/r/noarch

Do I have to install python 3.8.8? My actual python version is 3.10.6.

HugoSega commented 1 year ago
WARNING: md5sum mismatch of tar archive
expected: 41abe40ea68b8cba7668f9d0110eab4f
     got: 0961cd918a612915577461e6ac5696f9
Unpacking payload ...
/bin/bash: line 409: /Users/mkaiser/miniconda3/conda.exe: cannot execute binary file
/bin/bash: line 411: /Users/mkaiser/miniconda3/conda.exe: cannot execute binary file

You have installed the wrong conda version, it says conda.exe which is for windows. You need for macOS arm

Step 1 Completely remove miniconda rm -rf ~/opt/miniconda3 Clean additional configurations with: rm -rf ~/.condarc ~/.conda

Remove the path statement by using the vi terminal editor (delete everything inside this file. (to delete lines click D multiple times on your keyboard for each line vi ~/.bash_profile Once done, close vi terminal editor by pressing shift, colon :, and typewq hit enter.

Step 2 Install miniconda from this command

curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o Miniconda3-latest-MacOSX-arm64.sh
/bin/bash Miniconda3-latest-MacOSX-arm64.sh

Step 4 Create and activate a new conda environment named ml python -V this command will show you which version is installed on your computer conda create -n ml python=YOUR VERSION example: conda create -n ml python=3.9.13 conda activate ml Install the needed Python packages conda install pytorch torchvision torchaudio -c pytorch-nightly conda install transformers conda install -c conda-forge diffusers conda install ftfy

Install git and git-lfs via Homebrew brew install git git-lfs

Clone this repo and create an output folder git clone https://github.com/FahimF/sd-gui.git cd sd-gui mkdir output

Clone the Hugging Face model repo - you will need the Hugging Face user and password for this step git lfs install git clone https://huggingface.co/CompVis/stable-diffusion-v1-4

gimmel commented 1 year ago

Thank you. I already installed Miniconda3-latest-MacOSX-arm64.sh manually, but I did it again the way you recommended. I also removed /opt/miniconda3 (~/opt/miniconda3 did not exist).

But I still can’t create the condo environment:

~ % python -V                       
Python 3.10.6
~ % conda create -n ml python=3.10.6
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - python=3.10.6

Current channels:

  - https://repo.anaconda.com/pkgs/main/osx-arm64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/osx-arm64
  - https://repo.anaconda.com/pkgs/r/noarch

Conda seems not to use the installed python, but installs it from the available channels. I solved it by using the conda-forge channel: conda create --channel conda-forge -n ml python=3.10.6

gimmel commented 1 year ago

Now that the conda environment is finally working, the next problems occur.

~ % conda activate ml
(ml) ~ % conda install pytorch torchvision torchaudio -c pytorch-nightly

There are conflicts between the packages.

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                           

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versions

Package pytorch conflicts for:
pytorch
torchvision -> pytorch[version='1.10.2|1.13.0.dev20220917|1.13.0.dev20220918']
torchaudio -> pytorch==1.13.0.dev20220917

Package setuptools conflicts for:
python=3.10.6 -> pip -> setuptools
torchvision -> setuptools

Package typing-extensions conflicts for:
torchvision -> pytorch==1.10.2 -> typing-extensions
pytorch -> typing-extensions
HugoSega commented 1 year ago

reinstall torch conda install pytorch torchvision torchaudio -c pytorch-nightly --force-reinstall

I also would recommend python version 3.9.13. (anything under 3.10 version, for apple sillicon)

FahimF commented 1 year ago

I'm closing this issue since there has been no updates on this.