AbdBarho / stable-diffusion-webui-docker

Easy Docker setup for Stable Diffusion with user-friendly UI
Other
6.78k stars 1.13k forks source link

ImportError: cannot import name 'TypeIs' #719

Open guterresrafael opened 3 months ago

guterresrafael commented 3 months ago

Hi,

I have error on command "docker compose --profile auto up --build"

ImportError: cannot import name 'TypeIs' from 'typing_extensions' (/opt/conda/lib/python3.10/site-packages/typing_extensions.py)

Attaching to auto-1
auto-1  | /stable-diffusion-webui
auto-1  | total 772K
auto-1  | drwxr-xr-x  1 root root 4.0K Aug 12 19:09 .                                                                                                                                                                                                                       
auto-1  | drwxr-xr-x  1 root root 4.0K Aug 12 19:52 ..
auto-1  | -rw-r--r--  1 root root   48 Aug 12 19:06 .eslintignore                                                                                                                                                                                                           
auto-1  | -rw-r--r--  1 root root 3.4K Aug 12 19:06 .eslintrc.js                                                                                                                                                                                                            
auto-1  | drwxr-xr-x  8 root root 4.0K Aug 12 19:06 .git
auto-1  | -rw-r--r--  1 root root   55 Aug 12 19:06 .git-blame-ignore-revs                                                                                                                                                                                                  
auto-1  | drwxr-xr-x  4 root root 4.0K Aug 12 19:06 .github                                                                                                                                                                                                                 
auto-1  | -rw-r--r--  1 root root  521 Aug 12 19:06 .gitignore
auto-1  | -rw-r--r--  1 root root  119 Aug 12 19:06 .pylintrc                                                                                                                                                                                                               
auto-1  | -rw-r--r--  1 root root  84K Aug 12 19:06 CHANGELOG.md                                                                                                                                                                                                            
auto-1  | -rw-r--r--  1 root root  243 Aug 12 19:06 CITATION.cff
auto-1  | -rw-r--r--  1 root root  657 Aug 12 19:06 CODEOWNERS                                                                                                                                                                                                              
auto-1  | -rw-r--r--  1 root root  35K Aug 12 19:06 LICENSE.txt                                                                                                                                                                                                             
auto-1  | -rw-r--r--  1 root root  13K Aug 12 19:06 README.md
auto-1  | -rw-r--r--  1 root root  146 Aug 12 19:06 _typos.toml                                                                                                                                                                                                             
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 configs                                                                                                                                                                                                                 
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 embeddings
auto-1  | -rw-r--r--  1 root root  167 Aug 12 19:06 environment-wsl2.yaml                                                                                                                                                                                                   
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 extensions                                                                                                                                                                                                              
auto-1  | drwxr-xr-x 13 root root 4.0K Aug 12 19:06 extensions-builtin
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 html                                                                                                                                                                                                                    
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:09 interrogate
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 javascript                                                                                                                                                                                                              
auto-1  | -rw-r--r--  1 root root 1.3K Aug 12 19:06 launch.py                                                                                                                                                                                                               
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 localizations
auto-1  | drwxr-xr-x  7 root root 4.0K Aug 12 19:06 models                                                                                                                                                                                                                  
auto-1  | drwxr-xr-x  7 root root 4.0K Aug 12 19:06 modules
auto-1  | -rw-r--r--  1 root root  185 Aug 12 19:06 package.json                                                                                                                                                                                                            
auto-1  | -rw-r--r--  1 root root  841 Aug 12 19:06 pyproject.toml                                                                                                                                                                                                          
auto-1  | drwxr-xr-x  8 root root 4.0K Aug 12 18:18 repositories
auto-1  | -rw-r--r--  1 root root   49 Aug 12 19:06 requirements-test.txt                                                                                                                                                                                                   
auto-1  | -rw-r--r--  1 root root  371 Aug 12 19:06 requirements.txt
auto-1  | -rw-r--r--  1 root root   42 Aug 12 19:06 requirements_npu.txt                                                                                                                                                                                                    
auto-1  | -rw-r--r--  1 root root  645 Aug 12 19:06 requirements_versions.txt                                                                                                                                                                                               
auto-1  | -rw-r--r--  1 root root 411K Aug 12 19:06 screenshot.png
auto-1  | -rw-r--r--  1 root root 6.1K Aug 12 19:06 script.js                                                                                                                                                                                                               
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 scripts
auto-1  | -rw-r--r--  1 root root  43K Aug 12 19:06 style.css                                                                                                                                                                                                               
auto-1  | drwxr-xr-x  4 root root 4.0K Aug 12 19:06 test
auto-1  | drwxr-xr-x  2 root root 4.0K Aug 12 19:06 textual_inversion_templates                                                                                                                                                                                             
auto-1  | -rw-r--r--  1 root root  670 Aug 12 19:06 webui-macos-env.sh
auto-1  | -rw-r--r--  1 root root   84 Aug 12 19:06 webui-user.bat                                                                                                                                                                                                          
auto-1  | -rw-r--r--  1 root root 1.4K Aug 12 19:06 webui-user.sh
auto-1  | -rw-r--r--  1 root root 2.3K Aug 12 19:06 webui.bat
auto-1  | -rw-r--r--  1 root root 5.3K Aug 12 19:06 webui.py
auto-1  | -rwxr-xr-x  1 root root  11K Aug 12 19:06 webui.sh
auto-1  | Mounted .cache
auto-1  | Mounted config_states
auto-1  | mkdir: created directory '/stable-diffusion-webui/repositories/CodeFormer'
auto-1  | mkdir: created directory '/stable-diffusion-webui/repositories/CodeFormer/weights'
auto-1  | Mounted .cache
auto-1  | Mounted embeddings
auto-1  | Mounted config.json
auto-1  | Mounted models
auto-1  | Mounted styles.csv
auto-1  | Mounted ui-config.json
auto-1  | Mounted extensions
auto-1  | Installing extension dependencies (if any)
auto-1  | Traceback (most recent call last):
auto-1  |   File "/stable-diffusion-webui/webui.py", line 13, in <module>
auto-1  |     initialize.imports()
auto-1  |   File "/stable-diffusion-webui/modules/initialize.py", line 23, in imports
auto-1  |     import gradio  # noqa: F401
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/gradio/__init__.py", line 3, in <module>
auto-1  |     import gradio.components as components
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/gradio/components/__init__.py", line 3, in <module>
auto-1  |     from gradio.components.bar_plot import BarPlot
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/gradio/components/bar_plot.py", line 7, in <module>
auto-1  |     import altair as alt
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/__init__.py", line 650, in <module>
auto-1  |     from altair.vegalite import *
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/vegalite/__init__.py", line 2, in <module>
auto-1  |     from .v5 import *
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/vegalite/v5/__init__.py", line 2, in <module>
auto-1  |     from altair.expr.core import datum
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/expr/__init__.py", line 7, in <module>
auto-1  |     from altair.expr.core import ConstExpression, FunctionExpression
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/expr/core.py", line 6, in <module>
auto-1  |     from altair.utils import SchemaBase
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/utils/__init__.py", line 15, in <module>
auto-1  |     from .plugin_registry import PluginRegistry
auto-1  |   File "/opt/conda/lib/python3.10/site-packages/altair/utils/plugin_registry.py", line 6, in <module>
auto-1  |     from typing_extensions import TypeAliasType, TypeIs, TypeVar
auto-1  | ImportError: cannot import name 'TypeIs' from 'typing_extensions' (/opt/conda/lib/python3.10/site-packages/typing_extensions.py)
auto-1 exited with code 1
RNase777 commented 3 months ago

Same issue on Windows 10

pandaedward commented 3 months ago

I have the same error with profile auto under Debian. The build succeeded but container fails to start. Here is the full log:

/stable-diffusion-webui
total 772K
drwxr-xr-x  1 root root 4.0K Aug 12 20:48 .
drwxr-xr-x  1 root root 4.0K Aug 14 02:32 ..
-rw-r--r--  1 root root   48 Aug 12 20:46 .eslintignore
-rw-r--r--  1 root root 3.4K Aug 12 20:46 .eslintrc.js
drwxr-xr-x  8 root root 4.0K Aug 12 20:46 .git
-rw-r--r--  1 root root   55 Aug 12 20:46 .git-blame-ignore-revs
drwxr-xr-x  4 root root 4.0K Aug 12 20:46 .github
-rw-r--r--  1 root root  521 Aug 12 20:46 .gitignore
-rw-r--r--  1 root root  119 Aug 12 20:46 .pylintrc
-rw-r--r--  1 root root  84K Aug 12 20:46 CHANGELOG.md
-rw-r--r--  1 root root  243 Aug 12 20:46 CITATION.cff
-rw-r--r--  1 root root  657 Aug 12 20:46 CODEOWNERS
-rw-r--r--  1 root root  35K Aug 12 20:46 LICENSE.txt
-rw-r--r--  1 root root  13K Aug 12 20:46 README.md
-rw-r--r--  1 root root  146 Aug 12 20:46 _typos.toml
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 configs
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 embeddings
-rw-r--r--  1 root root  167 Aug 12 20:46 environment-wsl2.yaml
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 extensions
drwxr-xr-x 13 root root 4.0K Aug 12 20:46 extensions-builtin
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 html
drwxr-xr-x  2 root root 4.0K Aug 12 20:48 interrogate
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 javascript
-rw-r--r--  1 root root 1.3K Aug 12 20:46 launch.py
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 localizations
drwxr-xr-x  7 root root 4.0K Aug 12 20:46 models
drwxr-xr-x  7 root root 4.0K Aug 12 20:46 modules
-rw-r--r--  1 root root  185 Aug 12 20:46 package.json
-rw-r--r--  1 root root  841 Aug 12 20:46 pyproject.toml
drwxr-xr-x  8 root root 4.0K Aug 12 20:41 repositories
-rw-r--r--  1 root root   49 Aug 12 20:46 requirements-test.txt
-rw-r--r--  1 root root  371 Aug 12 20:46 requirements.txt
-rw-r--r--  1 root root   42 Aug 12 20:46 requirements_npu.txt
-rw-r--r--  1 root root  645 Aug 12 20:46 requirements_versions.txt
-rw-r--r--  1 root root 411K Aug 12 20:46 screenshot.png
-rw-r--r--  1 root root 6.1K Aug 12 20:46 script.js
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 scripts
-rw-r--r--  1 root root  43K Aug 12 20:46 style.css
drwxr-xr-x  4 root root 4.0K Aug 12 20:46 test
drwxr-xr-x  2 root root 4.0K Aug 12 20:46 textual_inversion_templates
-rw-r--r--  1 root root  670 Aug 12 20:46 webui-macos-env.sh
-rw-r--r--  1 root root   84 Aug 12 20:46 webui-user.bat
-rw-r--r--  1 root root 1.4K Aug 12 20:46 webui-user.sh
-rw-r--r--  1 root root 2.3K Aug 12 20:46 webui.bat
-rw-r--r--  1 root root 5.3K Aug 12 20:46 webui.py
-rwxr-xr-x  1 root root  11K Aug 12 20:46 webui.sh
Mounted .cache
Mounted config_states
mkdir: created directory '/stable-diffusion-webui/repositories/CodeFormer'
mkdir: created directory '/stable-diffusion-webui/repositories/CodeFormer/weights'
Mounted .cache
Mounted embeddings
Mounted config.json
Mounted models
Mounted styles.csv
Mounted ui-config.json
Mounted extensions
Installing extension dependencies (if any)
Traceback (most recent call last):
  File "/stable-diffusion-webui/webui.py", line 13, in <module>
    initialize.imports()
  File "/stable-diffusion-webui/modules/initialize.py", line 23, in imports
    import gradio  # noqa: F401
  File "/opt/conda/lib/python3.10/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio.components as components
  File "/opt/conda/lib/python3.10/site-packages/gradio/components/__init__.py", line 3, in <module>
    from gradio.components.bar_plot import BarPlot
  File "/opt/conda/lib/python3.10/site-packages/gradio/components/bar_plot.py", line 7, in <module>
    import altair as alt
  File "/opt/conda/lib/python3.10/site-packages/altair/__init__.py", line 650, in <module>
    from altair.vegalite import *
  File "/opt/conda/lib/python3.10/site-packages/altair/vegalite/__init__.py", line 2, in <module>
    from .v5 import *
  File "/opt/conda/lib/python3.10/site-packages/altair/vegalite/v5/__init__.py", line 2, in <module>
    from altair.expr.core import datum
  File "/opt/conda/lib/python3.10/site-packages/altair/expr/__init__.py", line 7, in <module>
    from altair.expr.core import ConstExpression, FunctionExpression
  File "/opt/conda/lib/python3.10/site-packages/altair/expr/core.py", line 6, in <module>
    from altair.utils import SchemaBase
  File "/opt/conda/lib/python3.10/site-packages/altair/utils/__init__.py", line 15, in <module>
    from .plugin_registry import PluginRegistry
  File "/opt/conda/lib/python3.10/site-packages/altair/utils/plugin_registry.py", line 6, in <module>
    from typing_extensions import TypeAliasType, TypeIs, TypeVar
ImportError: cannot import name 'TypeIs' from 'typing_extensions' (/opt/conda/lib/python3.10/site-packages/typing_extensions.py)
SongRongLee commented 3 months ago

Here's my investigation of the issue:

longunmin commented 3 months ago

Here's my investigation of the issue:

  • The problem is caused by altair update to v5.4.0, where higher requirement of typing_extensions>=4.10.0 is introduced (previously it was `typing_extensions>=4.0.1)
  • I further investigate the current packages installed in the container, there are two duplicated versions of tying_extensions, where typing_extensions.py belongs to version 4.9.0, and that's the version actually resolved. This is why altair cannot find its new TypeIs export.
drwxr-xr-x   2 root root    4096 Apr 24 16:17 typing_extensions-4.11.0.dist-info/
drwxr-xr-x   2 root root    4096 Apr 24 16:22 typing_extensions-4.9.0.dist-info/
-rw-r--r--   2 root root  110125 Jan 18  2024 typing_extensions.py
  • I start looking for where the duplicated packages got installed, and found that a fresh container from pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime already has these duplicated packages. I doubt that typing_extensions==4.9.0 comes with conda, but further investigation is needed. Hope someone can continue from here.
  • A workaround for this seems to be uninstalling all typing_extensions and reinstall typing_extensions==4.11.0 in the docker file. Need someone to confirm if this is a good solution.

Can you share your revised Dockerfile? Or where you are putting typing_extensions==4.11.0

yasu-nxt commented 3 months ago

I inserted it in this line of the Dockerfile and it is working in my environment.

https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/services/AUTOMATIC1111/Dockerfile#L41

Inserted are the following

RUN --mount=type=cache,target=/root/.cache/pip \
   pip uninstall -y typing_extensions && \
   pip install typing_extensions==4.11.0
loweryjk commented 3 months ago

The suggestion by @yasu-nxt worked for me.


RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate

RUN --mount=type=cache,target=/root/.cache/pip \
   pip uninstall -y typing_extensions && \
   pip install typing_extensions==4.11.0

RUN --mount=type=cache,target=/root/.cache/pip \
  pip install pyngrok xformers==0.0.26.post1 \
  git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \
  git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \
  git+https://github.com/mlfoundations/open_clip.git@v2.20.0```
fahadshery commented 2 months ago

I inserted it in this line of the Dockerfile and it is working in my environment.

https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/services/AUTOMATIC1111/Dockerfile#L41

Inserted are the following

RUN --mount=type=cache,target=/root/.cache/pip \
   pip uninstall -y typing_extensions && \
   pip install typing_extensions==4.11.0

This worked for me too.

Using Ubuntu.

JSpiner commented 2 months ago

RUN --mount=type=cache,target=/root/.cache/pip \ pip uninstall -y typing_extensions && \ pip install typing_extensions==4.11.0

this works for me too. Thanks!

hazrpg commented 2 months ago

Works for me too! Ubuntu 22.04

pandaedward commented 2 months ago

Confirmed fixed in debian 12.1

strannick-ru commented 2 months ago

Confirmed fixed in ubuntu 22.04

JervNorsk commented 2 months ago

I inserted it in this line of the Dockerfile and it is working in my environment. https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/services/AUTOMATIC1111/Dockerfile#L41 Inserted are the following

RUN --mount=type=cache,target=/root/.cache/pip \
   pip uninstall -y typing_extensions && \
   pip install typing_extensions==4.11.0

This worked for me too.

Using Ubuntu.

Confirmed fixed in Windows Docker Desktop 4.31.1 (WSL2)

feickoo commented 1 month ago

i fixed this by adding

# Add this line to update typing_extensions
RUN pip install --upgrade typing_extensions