Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: cannot import name 'Undefined' from 'pydantic.fields' (stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\fields.py) #717

Open
6 tasks
sunlery opened this issue May 9, 2024 · 9 comments

Comments

@sunlery
Copy link

sunlery commented May 9, 2024

Checklist

  • The issue exists after disabling all extensions
  • The issue exists on a clean installation of webui
  • The issue is caused by an extension, but I believe it is caused by a bug in the webui
  • The issue exists in the current version of the webui
  • The issue has not been reported before recently
  • The issue has been reported before but has not been fixed yet

What happened?

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: f0.0.17v1.8.0rc-latest-276-g29be1da7
Commit hash: 29be1da
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\forge_legacy_preprocessors\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\sd_forge_controlnet\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Launching Web UI with arguments: --gradio-allowed-path Data\Images
Total VRAM 6144 MB, total RAM 32620 MB
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3060 Laptop GPU : native
Hint: your device supports --pin-shared-memory for potential speed improvements.
Hint: your device supports --cuda-malloc for potential speed improvements.
Hint: your device supports --cuda-stream for potential speed improvements.
VAE dtype: torch.bfloat16
CUDA Stream Activated: False


launch.py 51
main()

launch.py 47 main
start()

launch_utils.py 541 start
import webui

webui.py 19
initialize.imports()

initialize.py 35 imports
import gradio # noqa: F401

init.py 3
import gradio.components as components

init.py 1
from gradio.components.annotated_image import AnnotatedImage

annotated_image.py 13
from gradio.components.base import IOComponent, _Keywords

base.py 20
from fastapi import UploadFile

init.py 7
from .applications import FastAPI as FastAPI

applications.py 15
from fastapi import routing

routing.py 22
from fastapi import params

params.py 4
from pydantic.fields import FieldInfo, Undefined

ImportError:
cannot import name 'Undefined' from 'pydantic.fields' (Data\Packages\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\fields.py)

Steps to reproduce the problem

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: f0.0.17v1.8.0rc-latest-276-g29be1da7
Commit hash: 29be1da
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\forge_legacy_preprocessors\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\sd_forge_controlnet\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Launching Web UI with arguments: --gradio-allowed-path Data\Images
Total VRAM 6144 MB, total RAM 32620 MB
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3060 Laptop GPU : native
Hint: your device supports --pin-shared-memory for potential speed improvements.
Hint: your device supports --cuda-malloc for potential speed improvements.
Hint: your device supports --cuda-stream for potential speed improvements.
VAE dtype: torch.bfloat16
CUDA Stream Activated: False


launch.py 51
main()

launch.py 47 main
start()

launch_utils.py 541 start
import webui

webui.py 19
initialize.imports()

initialize.py 35 imports
import gradio # noqa: F401

init.py 3
import gradio.components as components

init.py 1
from gradio.components.annotated_image import AnnotatedImage

annotated_image.py 13
from gradio.components.base import IOComponent, _Keywords

base.py 20
from fastapi import UploadFile

init.py 7
from .applications import FastAPI as FastAPI

applications.py 15
from fastapi import routing

routing.py 22
from fastapi import params

params.py 4
from pydantic.fields import FieldInfo, Undefined

ImportError:
cannot import name 'Undefined' from 'pydantic.fields' (Data\Packages\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\fields.py)

What should have happened?

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: f0.0.17v1.8.0rc-latest-276-g29be1da7
Commit hash: 29be1da
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\forge_legacy_preprocessors\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\sd_forge_controlnet\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Launching Web UI with arguments: --gradio-allowed-path Data\Images
Total VRAM 6144 MB, total RAM 32620 MB
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3060 Laptop GPU : native
Hint: your device supports --pin-shared-memory for potential speed improvements.
Hint: your device supports --cuda-malloc for potential speed improvements.
Hint: your device supports --cuda-stream for potential speed improvements.
VAE dtype: torch.bfloat16
CUDA Stream Activated: False


launch.py 51
main()

launch.py 47 main
start()

launch_utils.py 541 start
import webui

webui.py 19
initialize.imports()

initialize.py 35 imports
import gradio # noqa: F401

init.py 3
import gradio.components as components

init.py 1
from gradio.components.annotated_image import AnnotatedImage

annotated_image.py 13
from gradio.components.base import IOComponent, _Keywords

base.py 20
from fastapi import UploadFile

init.py 7
from .applications import FastAPI as FastAPI

applications.py 15
from fastapi import routing

routing.py 22
from fastapi import params

params.py 4
from pydantic.fields import FieldInfo, Undefined

ImportError:
cannot import name 'Undefined' from 'pydantic.fields' (Data\Packages\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\fields.py)

What browsers do you use to access the UI ?

No response

Sysinfo

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: f0.0.17v1.8.0rc-latest-276-g29be1da7
Commit hash: 29be1da
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\forge_legacy_preprocessors\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\sd_forge_controlnet\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Launching Web UI with arguments: --gradio-allowed-path Data\Images
Total VRAM 6144 MB, total RAM 32620 MB
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3060 Laptop GPU : native
Hint: your device supports --pin-shared-memory for potential speed improvements.
Hint: your device supports --cuda-malloc for potential speed improvements.
Hint: your device supports --cuda-stream for potential speed improvements.
VAE dtype: torch.bfloat16
CUDA Stream Activated: False


launch.py 51
main()

launch.py 47 main
start()

launch_utils.py 541 start
import webui

webui.py 19
initialize.imports()

initialize.py 35 imports
import gradio # noqa: F401

init.py 3
import gradio.components as components

init.py 1
from gradio.components.annotated_image import AnnotatedImage

annotated_image.py 13
from gradio.components.base import IOComponent, _Keywords

base.py 20
from fastapi import UploadFile

init.py 7
from .applications import FastAPI as FastAPI

applications.py 15
from fastapi import routing

routing.py 22
from fastapi import params

params.py 4
from pydantic.fields import FieldInfo, Undefined

ImportError:
cannot import name 'Undefined' from 'pydantic.fields' (Data\Packages\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\fields.py)

Console logs

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: f0.0.17v1.8.0rc-latest-276-g29be1da7
Commit hash: 29be1da7cf2b5dccfc70fbdd33eb35c56a31ffb7
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\forge_legacy_preprocessors\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
Data\Packages\stable-diffusion-webui-forge\extensions-builtin\sd_forge_controlnet\install.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
Launching Web UI with arguments: --gradio-allowed-path Data\Images
Total VRAM 6144 MB, total RAM 32620 MB
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3060 Laptop GPU : native
Hint: your device supports --pin-shared-memory for potential speed improvements.
Hint: your device supports --cuda-malloc for potential speed improvements.
Hint: your device supports --cuda-stream for potential speed improvements.
VAE dtype: torch.bfloat16
CUDA Stream Activated:  False

-------------------------------------------------------------------------------
launch.py 51 <module>
main()

launch.py 47 main
start()

launch_utils.py 541 start
import webui

webui.py 19 <module>
initialize.imports()

initialize.py 35 imports
import gradio  # noqa: F401

__init__.py 3 <module>
import gradio.components as components

__init__.py 1 <module>
from gradio.components.annotated_image import AnnotatedImage

annotated_image.py 13 <module>
from gradio.components.base import IOComponent, _Keywords

base.py 20 <module>
from fastapi import UploadFile

__init__.py 7 <module>
from .applications import FastAPI as FastAPI

applications.py 15 <module>
from fastapi import routing

routing.py 22 <module>
from fastapi import params

params.py 4 <module>
from pydantic.fields import FieldInfo, Undefined

ImportError:
cannot import name 'Undefined' from 'pydantic.fields' (Data\Packages\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\fields.py)

Additional information

No response

@gunser12
Copy link

gunser12 commented May 9, 2024

+1

I tried to install using stability matrix in the same way and in the usual way, and everything happened the same way with the same error

Python:3.10.6
RTX 3090 Ti
Driver 552.22

@kamelohr
Copy link

kamelohr commented May 9, 2024

+1 Fresh install and got the same error on Win 11 (RTX 2080 Super).

However I managed to get it going with this workaround:

X:\ABSOLUTE_PATH_TO_INSTALLATION_ROOT\venv\Scripts\python.exe -m pip install pydantic@1.10.15

This answer gave me the hint to downgrade pydantic to V1.x and although it threw a dependency warning, it worked afterwards.

 E:\stable-diffusion-webui\venv\Scripts\python.exe -m pip install pydantic==1.10.15
Collecting pydantic==1.10.15
  Using cached pydantic-1.10.15-cp310-cp310-win_amd64.whl (2.1 MB)
Requirement already satisfied: typing-extensions>=4.2.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from pydantic==1.10.15) (4.11.0)
Installing collected packages: pydantic
  Attempting uninstall: pydantic
    Found existing installation: pydantic 2.7.1
    Uninstalling pydantic-2.7.1:
      Successfully uninstalled pydantic-2.7.1
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
albumentations 1.4.6 requires pydantic>=2.7.0, but you have pydantic 1.10.15 which is incompatible.
Successfully installed pydantic-1.10.15

@mariodian
Copy link

This is an issue with fastapi. In my case the setup broke down after installing insightface.

You can fix it by going to the venv/bin, activating the venv by source activate (on linux/mac at least) and updating fastapi to the latest version: pip install fastapi==0.111.0

@Alluseri
Copy link

Alluseri commented May 12, 2024

Can confirm the issue is there but @kamelohr's fix worked. Added pydantic==1.10.15 to requirements_versions.txt.

@Vidyut
Copy link

Vidyut commented May 14, 2024

+1 same issue. Trying @kamelohr's fix, but doesn't seem to be working. Python 3.10 or 3.11? I have ubuntu 24.04 fresh install, so the system python is 3.12. Using pyenv.

@kamelohr
Copy link

@Vidyut You might also try to install fastapi==0.111.0 as @mariodian wrote.
In fact, that's what I tried out as well (reverting to pydantic 2.7.1 and then installing fastapi v0.111.0 with
X:\ABSOLUTE_PATH_TO_INSTALLATION_ROOT\venv\Scripts\python.exe -m pip install fastapi@v0.111.0) and it worked.

I had Python 3.10 working on my system level but don't know what version that pyenv had (I'm at another machine atm).
Hope this helps.

@Vidyut
Copy link

Vidyut commented May 14, 2024

Thanks. Amazing. It's working now. Fingers crossed.

@SkyYap
Copy link

SkyYap commented May 15, 2024

@kamelohr method doesn't work for me but @mariodian method works for me. I just manually run pip install fastapi==0.111.0 and reopen the webui-user.bat and it works.

@Husky110
Copy link

Husky110 commented May 16, 2024

Both possible solutions do not work for me...
By using @kamelohr I can't use InstantID and using @mariodian leaves me with this on startup:

Using xformers cross attention
*** Error loading script: controlnet.py
    Traceback (most recent call last):
      File "/webuis/forge/modules/scripts.py", line 544, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "/webuis/forge/modules/script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/webuis/forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py", line 10, in <module>
        from modules.api.api import decode_base64_to_image
      File "/webuis/forge/modules/api/api.py", line 23, in <module>
        from modules.api import models
      File "/webuis/forge/modules/api/models.py", line 113, in <module>
        ).generate_model()
      File "/webuis/forge/modules/api/models.py", line 96, in generate_model
        DynamicModel.__config__.allow_population_by_field_name = True
      File "/venvs/forge/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 242, in __getattr__
        raise AttributeError(item)
    AttributeError: __config__

Some clarification - i'm starting forge via a start-script. Here's the relevant code:

(
  source "$FORGE_VENV_PATH/bin/activate"
  pip install insightface
  pip install pydantic==2.7.1
  pip install fastapi==0.111.0
)
echo -e "\033[0;36mReady to start FORGE-WebUI...\033[0m"
cd /webuis/forge && ./webui.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants