AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
136.34k stars 25.99k forks source link

[Bug]: RuntimeError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports' #11648

Open roxas122 opened 1 year ago

roxas122 commented 1 year ago

Is there an existing issue for this?

What happened?

Use Google Colab and run into problems: cannot import name '_compare_version' from 'torchmetrics.utilities.imports'

Steps to reproduce the problem

  1. Use Google Colab
  2. Clone the repo using git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
  3. run %pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117
  4. run !git checkout 11d432d
  5. Start the webui-user.bat

What should have happened?

The Web-UI should have launched without any errors.

Version or Commit where the problem happens

11d432d

What Python version are you running on ?

None

What platforms do you use to access the UI ?

Windows

What device are you running WebUI on?

No response

Cross attention optimization

Automatic

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

--share --gradio-debug --disable-safe-unpickle --reinstall-xformers --enable-insecure-extension-access --opt-channelslast

List of extensions

No

Console logs

Traceback (most recent call last):
  File "/content/test1/launch.py", line 295, in <module>
    start()
  File "/content/test1/launch.py", line 286, in start
    import webui
  File "/content/test1/webui.py", line 15, in <module>
    from modules import shared, devices, sd_samplers, upscaler, extensions, localization, ui_tempdir
  File "/content/test1/modules/sd_samplers.py", line 12, in <module>
    from modules import prompt_parser, devices, processing, images, sd_vae_approx
  File "/content/test1/modules/processing.py", line 15, in <module>
    import modules.sd_hijack
  File "/content/test1/modules/sd_hijack.py", line 4, in <module>
    import modules.textual_inversion.textual_inversion
  File "/content/test1/modules/textual_inversion/textual_inversion.py", line 13, in <module>
    from modules import shared, devices, sd_hijack, processing, sd_models, images, sd_samplers
  File "/content/test1/modules/sd_models.py", line 18, in <module>
    from modules.sd_hijack_inpainting import do_inpainting_hijack, should_hijack_inpainting
  File "/content/test1/modules/sd_hijack_inpainting.py", line 7, in <module>
    import ldm.models.diffusion.ddpm
  File "/content/test1/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py", line 12, in <module>
    import pytorch_lightning as pl
  File "/usr/local/lib/python3.10/dist-packages/pytorch_lightning/__init__.py", line 34, in <module>
    from pytorch_lightning.callbacks import Callback  # noqa: E402
  File "/usr/local/lib/python3.10/dist-packages/pytorch_lightning/callbacks/__init__.py", line 25, in <module>
    from pytorch_lightning.callbacks.progress import ProgressBarBase, RichProgressBar, TQDMProgressBar
  File "/usr/local/lib/python3.10/dist-packages/pytorch_lightning/callbacks/progress/__init__.py", line 22, in <module>
    from pytorch_lightning.callbacks.progress.rich_progress import RichProgressBar  # noqa: F401
  File "/usr/local/lib/python3.10/dist-packages/pytorch_lightning/callbacks/progress/rich_progress.py", line 20, in <module>
    from torchmetrics.utilities.imports import _compare_version
ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports' (/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/imports.py)

Additional information

I don't know programming so don't know how to try to fix. I would like to keep using 11d432d if I could.

flistz commented 1 year ago

I had the same problem and it seems to be a fairly new bug. Can't find answers to related questions on google.

slowargo commented 1 year ago

try downgrade torchmetrics to torchmetrics==0.11.4

roxas122 commented 1 year ago

try downgrade torchmetrics to torchmetrics==0.11.4

it work! thank you so much!

jmaiap commented 1 year ago

Having the same problem. How did you downgrade it?

michaelNinh commented 1 year ago

@jmaiap put torchmetrics==0.11.4 in either requirements.txt or requirements_version.txt. I put it in both so not sure which one fixed it.

jmaiap commented 1 year ago

I'm sorry but i'm a total noob, where are those files located?

DedrickCheng commented 1 year ago

Same problem here, don't know how to fix this issue :(

DedrickCheng commented 1 year ago

I think maybe we should add the line in the code.

image

XtheCutter commented 1 year ago

Having same problem: ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports' (/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/imports.py)

I cant even uderstand where are this files localed:) I added torchmetrics 0.11.4 upgrade but didnt help

infinitedarkw commented 1 year ago

@jmaiap put torchmetrics==0.11.4 in either requirements.txt or requirements_version.txt. I put it in both so not sure which one fixed it.

Where are the requirements.txt or requirements_version.txt located at? I am having the same issue, I need a little guidance on where to edit the file/s? Can someone offer some steps? Most grateful in advance...

bugbug0102 commented 1 year ago

for people running on google colab, once clean the runtime and add the torchmetrics==0.11.4 under pip install, then it would be working. !pip install torchmetrics==0.11.4 torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117

aeolonan commented 1 year ago

for people running on google colab, once clean the runtime and add the torchmetrics==0.11.4 under pip install, then it would be working. !pip install torchmetrics==0.11.4 torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117

Thx,it works~

nmeligari commented 1 year ago

for people running on google colab, once clean the runtime and add the torchmetrics==0.11.4 under pip install, then it would be working. !pip install torchmetrics==0.11.4 torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117

Any thoughts for those of us running it locally (as opposed to on google colab)? I'm getting the same error and I'm trying to run it on my local machine. Thanks in advance!

daiju12 commented 1 year ago

@jmaiaptorchmetrics==0.11.4 をrequirements.txtまたはrequirements_version.txtのいずれかに入力します。両方入れたのでどちらで直ったかは分かりません。

requirements.txt またはrequirements_version.txt はどこにありますか? 同じ問題が発生しています。ファイルを編集する場所について少し説明が必要ですか? 誰かがいくつかの手順を提供できますか? よろしくお願いいたします...

私のローカル環境ではファイルはここにありました。 *ドライブレターとインストール先はご自身の環境に読み替えてください。 A:\StableDiffusion\sd.webui\webui\requirements.txt A:\StableDiffusion\sd.webui\webui\requirements_versions.txt

両方のファイルにこれを記述して改善しました。 torchmetrics==0.11.4

ShivangiP commented 1 year ago

I am getting similar error : 17 from datetime import timedelta 18 from typing import Any, Dict, Optional, Union ---> 20 from torchmetrics.utilities.imports import _compare_version 22 import pytorch_lightning as pl 23 from pytorch_lightning.callbacks.progress.base import ProgressBarBase

ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/torchmetrics/utilities/imports.py)

I tried all the above suggestion but nothing is working. Please help.

XtheCutter commented 1 year ago

for people running on google colab, once clean the runtime and add the torchmetrics==0.11.4 under pip install, then it would be working. !pip install torchmetrics==0.11.4 torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117

Done it But still have this ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports' (/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/imports.py)

NaClZhang commented 1 year ago

Add “torchmetrics==0.11.4” in red circle WeChatc4d2b272027743541dfb53e1a9125e64

nekopunch11 commented 1 year ago

Add “torchmetrics==0.11.4” in red circle在红色圆圈中添加“火炬度量==0.11.4” WeChatc4d2b272027743541dfb53e1a9125e64

ty,very useful

CCMonkeyss commented 1 year ago

It works, thanks a lot!

janily commented 1 year ago

It works, thanks a lot! How is this problem solved ? I still can't make it work following the method above.

CCMonkeyss commented 1 year ago

It works, thanks a lot! How is this problem solved ? I still can't make it work following the method above.

just add this "torchmetrics==0.11.4" to your torch install command.

burn4science commented 1 year ago

If you're working in Docker containers follow this solution to adjust the version of torchmetrics: https://github.com/AbdBarho/stable-diffusion-webui-docker/issues/540#issuecomment-1625697493

Spawn888 commented 1 year ago

Not all installers are gonna have that "requierements" folder. Mine doesn't. Upgrading to 0.11.4 does nothing.

Reibubba commented 1 year ago

Same problem - running Windows and erroring out with the Torchmetrics error. For the sake of the terminal Luddite that I am, can anyone provide clean and concise instructions to cure it on Windows please?

emuyia commented 1 year ago

can anyone provide clean and concise instructions to cure it on Windows please?

Not all installers are gonna have that "requierements" folder. Mine doesn't. Upgrading to 0.11.4 does nothing.

@Spawn888 @Reibubba After installing with the bat or sh, open the invokeai folder in terminal or cmd and run source .venv/bin/activate (or in Windows: .venv\Scripts\activate), then pip install torchmetrics==0.11.4. That worked for me.

SheldonWxy commented 1 year ago

It doesn't work in my project. I have tried to add it into requriments.txt with version and without version, or just install by pip with version and without version. All of those doesn't work. What could I do?

screenshot-20230719-104310 screenshot-20230719-104419 screenshot-20230719-104434

hard-tek commented 1 year ago

Is there is fix on Archlinux? mportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports' (/home/ht/invokeai/.venv/lib/python3.10/site-packages/torchmetrics/utilities/imports.py)

SheldonWxy commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。

sct123 commented 1 year ago

can anyone provide clean and concise instructions to cure it on Windows please?

Not all installers are gonna have that "requierements" folder. Mine doesn't. Upgrading to 0.11.4 does nothing.

@Spawn888 @Reibubba After installing with the bat or sh, open the invokeai folder in terminal or cmd and run source .venv/bin/activate (or in Windows: .venv\Scripts\activate), then pip install torchmetrics==0.11.4. That worked for me. it work.thank you very much.it in mac pro.

justanoob00 commented 12 months ago

can anyone provide clean and concise instructions to cure it on Windows please?

Not all installers are gonna have that "requierements" folder. Mine doesn't. Upgrading to 0.11.4 does nothing.

@Spawn888 @Reibubba After installing with the bat or sh, open the invokeai folder in terminal or cmd and run source .venv/bin/activate (or in Windows: .venv\Scripts\activate), then pip install torchmetrics==0.11.4. That worked for me.

Hi, as my name shows, I'm a total noob. So I tried doing what you said on my local machine and then it says " The module '.venv' could not be loaded. For more information, run 'Import-Module .venv'"

this is running terminal on the folder itself and also on the install bat file.

Then I just skipped to install torch 0.11.4 and it says it's already installed.

And of course none of this works to fully install invoke. Any further help would be much appreciated.

emuyia commented 12 months ago

Hi, as my name shows, I'm a total noob. So I tried doing what you said on my local machine and then it says " The module '.venv' could not be loaded. For more information, run 'Import-Module .venv'"

this is running terminal on the folder itself and also on the install bat file.

Then I just skipped to install torch 0.11.4 and it says it's already installed.

And of course none of this works to fully install invoke. Any further help would be much appreciated.

From that error message it sounds like you're using powershell, which would make sense as I think terminal in windows defaults to using powershell.

In that case you should try .venv\Scripts\Activate.ps1 rather than .venv\Scripts\activate. Then you should be able to run pip install torchmetrics==0.11.4.

Also make sure you're inside the invokeai folder when you do this. You can get there with cd "path" where path is the path to the invokeai folder. For example, if your username is John, and invokeai is located in your user directory, you'd use cd "C:\Users\John\invokeai".

If .venv\Scripts\Activate.ps1 gives you trouble just try using command prompt instead and go with .venv\Scripts\activate.

Hope this helps.

iamhazel commented 12 months ago

Had this problem trying to install/run it locally. Just had to run updates.bat then run.bat a second time and it fixed it.

Noobdaddy626 commented 12 months ago

can anyone please help me. I have no idea what any of this means? where do I input that code. speak to me like a child .

Spawn888 commented 12 months ago

For the people having trouble. I was in the same boat nothing I did solved anything. I just went ahead and followed the one click install video on youtube by aiimages and it works. Just make sure you use a third party unzip tool when extracting the files.

PowZone commented 11 months ago

Solved upgrading libs (DedrickCheng comment), than updating webui from GIT

pip install -q torch==2.0.0+cu118 torchmetrics==0.11.4 torchvision==0.15.1+cu118 torchaudio==2.0.1+cu118 torchtext==0.15.1 torchdata==0.6.0 --extra-index-url https://download.pytorch.org/whl/cu118 -U

pip install -q xformers==0.0.19 triton==2.0.0 -U    

git -C "webui" pull

webui-user.bat
CallMeFrozenBanana commented 11 months ago

ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports’ I modify the source code of rich_progress.py and fix this error: In the venv/lib/python3.8/site-packages/pytorch_lightning/callbacks/progress/richprogress.py delete the '\' of '_compare_version': image

will5933 commented 11 months ago

ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports’ I modify the source code of rich_progress.py and fix this error: In the venv/lib/python3.8/site-packages/pytorch_lightning/callbacks/progress/richprogress.py delete the '' of '_compare_version': image

thanks! it really works!!

UntrustWasTaken commented 11 months ago

ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports’ I modify the source code of rich_progress.py and fix this error: In the venv/lib/python3.8/site-packages/pytorch_lightning/callbacks/progress/richprogress.py delete the '' of '_compare_version': image

Legend! Finally got it working again for me. massive respect

JohnSmidlow commented 11 months ago

ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports’ I modify the source code of rich_progress.py and fix this error: In the venv/lib/python3.8/site-packages/pytorch_lightning/callbacks/progress/richprogress.py delete the '' of '_compare_version': image Screenshot 2023-08-21 100755

hey what if I simply don't have "compare_version" lines in rich_progress.py?

CallMeFrozenBanana commented 11 months ago

lines in rich_progress.py Emmm.. May you checks the contents of RequirementCache? And my pytorch-lightning version is 1.9.4

JohnSmidlow commented 11 months ago

lines in rich_progress.py Emmm.. May you checks the contents of RequirementCache? And my pytorch-lightning version is 1.9.4

I was confused, sorry, i tried your solution and it worked. Thank you

Khvgvni commented 10 months ago

Still have this problem. Help pls. Adding this text "torchmetrics==0.11.4" didn`t help((

ImportError Traceback (most recent call last) in <cell line: 12>() 10 import io 11 import math ---> 12 import timm 13 from IPython import display 14 import lpips

17 frames /usr/local/lib/python3.10/dist-packages/PIL/ImageFont.py in 32 33 from . import Image ---> 34 from ._util import isDirectory, isPath 35 36 LAYOUT_BASIC = 0

ImportError: cannot import name 'isDirectory' from 'PIL._util' (/usr/local/lib/python3.10/dist-packages/PIL/_util.py)


NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the "Open Examples" button below.

indusguys commented 10 months ago

try downgrade torchmetrics to torchmetrics==0.11.4

I don't know how to downgrade, none of this means anything, people say "pip install torchmetrics==0.11.4" but, where? Any folder on my PC, the rout webui for stable diffusion. Someone said uninstall torchmetrics, but how? I've tried the pip install in the venv folder and I've tried in the rout webui folder but, I'm still getting this same error. I've even tried a clean install of the aug 1st install for SD but I'm still getting the same issue. I've deleted the venv folder and I get the same issue. Actually I've had several issues that may as well be written in Cantonese for all I understand them. I never used a PC until a couple of years ago. I've always used Macs so this is all just blahdiblah to me. Please help. I am royally regretting updating my SD yesterday morning. How do you know if you're going to be downloading a whole heap of trouble? Thanks.

indusguys commented 10 months ago

try downgrade torchmetrics to torchmetrics==0.11.4

it work! thank you so much!

How do you downgrade tormetrics, I've tried: pip install torchmetrics==0.11.4 but, where do you put it? In venv in the webui rout folder? Where do you put it?

Wuverul commented 9 months ago

ImportError: cannot import name '_compare_version' from 'torchmetrics.utilities.imports’ I modify the source code of rich_progress.py and fix this error: In the venv/lib/python3.8/site-packages/pytorch_lightning/callbacks/progress/richprogress.py delete the '' of '_compare_version': image Screenshot 2023-08-21 100755

hey what if I simply don't have "compare_version" lines in rich_progress.py?

I very much want to +1 this. Removing the "_" in the instances on lines 20 and 26 fixed this error for me after a fresh download via the deployment package.

Edit: Actually, that only fixed half the issue. I now have another issue saying it can't add middleware, which seems to come from application.py on line 139? I'm not sure why that's returning as None, though, raising the exception. It should in theory be being set on line 121...

SheldonWxy commented 9 months ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。

weishaoah commented 9 months ago

for people running on google colab, once clean the runtime and add the torchmetrics==0.11.4 under pip install, then it would be working. !pip install torchmetrics==0.11.4 torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchtext==0.14.1 torchaudio==0.13.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu117

it works, thanks!

SheldonWxy commented 9 months ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。

hedachun321 commented 8 months ago

try downgrade torchmetrics to torchmetrics==0.11.4

thank you!the issue has been resolved. I performed the following actions: pip uninstall torchmetrics pip install torchmetrics==0.11.4

SheldonWxy commented 8 months ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。