AUTOMATIC1111 / stable-diffusion-webui

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

[Bug]: ImportError: DLL load failed while importing cv2: The specified module could not be found. #11657

Closed Damon-Turning closed 1 year ago

Damon-Turning commented 1 year ago

Is there an existing issue for this?

What happened?

I've installed the webui having met the dependencies and followed the instructions precisely, and I get the error "ImportError: DLL load failed while importing cv2: The specified module could not be found." This error has plagued me since Monday night. This is my second PC. My main rig is comfortably running SD and has been since September of last year. I'm comfortable with the UI and the CLI. I do not know how to write code.

More context - I'm trying this on a fresh install of Windows 10 with all updates and dependencies. I've tried with a fresh install of windows and follwing all steps about 5 times, literally. Nothing about my approach is casual, I have tried and tried. Searching for this particular error has yielded virtually no solutions for me as the context has always been other software.

I've ONLY assumed that the WebUI might be at fault after exhausting my capabilities.

Steps to reproduce the problem

  1. Go to .... https://github.com/AUTOMATIC1111/stable-diffusion-webui and follow the instructions for installing the webui on windows

  2. run webui-user.bat

  3. recieve error "ImportError: DLL load failed while importing cv2: The specified module could not be found."

What should have happened?

Well just as it should be and has in the past I should have had a complete installation at the end of the above procedure.

Version or Commit where the problem happens

1.4.0

What Python version are you running on ?

Python 3.10.x

What platforms do you use to access the UI ?

Windows, Linux

What device are you running WebUI on?

Nvidia GPUs (RTX 20 above)

Cross attention optimization

Automatic

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

no

List of extensions

none yet...

Console logs

Already up to date.
Creating venv in directory C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\venv using python "C:\Users\Beelzebub\AppData\Local\Programs\Python\Python310\python.exe"
venv "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]
Version: v1.4.0
Commit hash: 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8
Installing torch and torchvision
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118
Collecting torch==2.0.1
  Downloading https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-win_amd64.whl (2619.1 MB)
     ---------------------------------------- 2.6/2.6 GB 954.9 kB/s eta 0:00:00
Collecting torchvision==0.15.2
  Downloading https://download.pytorch.org/whl/cu118/torchvision-0.15.2%2Bcu118-cp310-cp310-win_amd64.whl (4.9 MB)
     ---------------------------------------- 4.9/4.9 MB 2.1 MB/s eta 0:00:00
Collecting networkx
  Using cached networkx-3.1-py3-none-any.whl (2.1 MB)
Collecting typing-extensions
  Using cached typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting jinja2
  Downloading https://download.pytorch.org/whl/Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ---------------------------------------- 133.1/133.1 kB 2.0 MB/s eta 0:00:00
Collecting filelock
  Using cached filelock-3.12.2-py3-none-any.whl (10 kB)
Collecting sympy
  Downloading sympy-1.12-py3-none-any.whl (5.7 MB)
     ---------------------------------------- 5.7/5.7 MB 1.2 MB/s eta 0:00:00
Collecting numpy
  Downloading numpy-1.25.0-cp310-cp310-win_amd64.whl (15.0 MB)
     ---------------------------------------- 15.0/15.0 MB 3.1 MB/s eta 0:00:00
Collecting pillow!=8.3.*,>=5.3.0
  Downloading Pillow-10.0.0-cp310-cp310-win_amd64.whl (2.5 MB)
     ---------------------------------------- 2.5/2.5 MB 2.9 MB/s eta 0:00:00
Collecting requests
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ---------------------------------------- 62.6/62.6 kB 1.1 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Using cached MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl (17 kB)
Collecting certifi>=2017.4.17
  Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)
     ---------------------------------------- 157.0/157.0 kB 2.3 MB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.0.3-py3-none-any.whl (123 kB)
     ---------------------------------------- 123.6/123.6 kB 3.7 MB/s eta 0:00:00
Collecting idna<4,>=2.5
  Using cached https://download.pytorch.org/whl/idna-3.4-py3-none-any.whl (61 kB)
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.1.0-cp310-cp310-win_amd64.whl (97 kB)
     ---------------------------------------- 97.1/97.1 kB 2.8 MB/s eta 0:00:00
Collecting mpmath>=0.19
  Downloading mpmath-1.3.0-py3-none-any.whl (536 kB)
     ---------------------------------------- 536.2/536.2 kB 2.6 MB/s eta 0:00:00
Installing collected packages: mpmath, urllib3, typing-extensions, sympy, pillow, numpy, networkx, MarkupSafe, idna, filelock, charset-normalizer, certifi, requests, jinja2, torch, torchvision
Successfully installed MarkupSafe-2.1.3 certifi-2023.5.7 charset-normalizer-3.1.0 filelock-3.12.2 idna-3.4 jinja2-3.1.2 mpmath-1.3.0 networkx-3.1 numpy-1.25.0 pillow-10.0.0 requests-2.31.0 sympy-1.12 torch-2.0.1+cu118 torchvision-0.15.2+cu118 typing-extensions-4.7.1 urllib3-2.0.3

[notice] A new release of pip available: 22.3.1 -> 23.1.2
[notice] To update, run: C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip
Installing gfpgan
Installing clip
Installing open_clip
Cloning Stable Diffusion into C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\repositories\stable-diffusion-stability-ai...
Cloning K-diffusion into C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\repositories\k-diffusion...
Cloning CodeFormer into C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\repositories\CodeFormer...
Cloning BLIP into C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\repositories\BLIP...
Installing requirements for CodeFormer
Installing requirements
Launching Web UI with arguments: --opt-split-attention
No module 'xformers'. Proceeding without it.
Traceback (most recent call last):
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\launch.py", line 38, in <module>
    main()
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\launch.py", line 34, in main
    start()
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\modules\launch_utils.py", line 340, in start
    import webui
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\webui.py", line 49, in <module>
    from modules import shared, sd_samplers, upscaler, extensions, localization, ui_tempdir, ui_extra_networks, config_states
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\modules\sd_samplers.py", line 1, in <module>
    from modules import sd_samplers_compvis, sd_samplers_kdiffusion, shared
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\modules\sd_samplers_compvis.py", line 9, in <module>
    from modules import sd_samplers_common, prompt_parser, shared
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\modules\sd_samplers_common.py", line 5, in <module>
    from modules import devices, processing, images, sd_vae_approx, sd_samplers, sd_vae_taesd
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\modules\processing.py", line 12, in <module>
    import cv2
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\venv\lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\Beelzebub\Stable Diffusion WebUI\stable-diffusion-webui\venv\lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "C:\Users\Beelzebub\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.
Press any key to continue . . .

Additional information

I am using absolutely fresh windows installs fully updated all official Pro N. I have tried more times than is reasonable. I've tried more than one approach. I tried twice on Ubuntu and twice on Linux Mint and failed for other reasons - I am willing to do just about anything to get this working. Though I can't code I am also willing to search and read anything anyone shares with me. The machine in question was purpose built for SD from older equipment I have and a new MOBO and RAM. 32G RAM. i7 4790K.

Damon-Turning commented 1 year ago

Now I have tried the approach in this reddit thread and I am still getting the same error:

https://old.reddit.com/r/StableDiffusion/comments/14sa3u0/ive_reinstalled_windows_and_all_dependencies/

Damon-Turning commented 1 year ago

I resolved this by adding the Windows Media Feature Pack. I read the suggestion somewhere and tried it and now my install boots up super fast.