stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: I get this error when I run python webui.py and facelib cannot install

Open eric-hsu opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

Error setting up CodeFormer: Traceback (most recent call last): File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\modules\codeformer_model.py", line 38, in setup_model from facelib.utils.face_restoration_helper import FaceRestoreHelper File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\utils\face_restoration_helper.py", line 7, in from facelib.detection import init_detection_model File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\detection_init_.py", line 10, in from .retinaface.retinaface import RetinaFace File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\detection\retinaface\retinaface.py", line 14, in from basicsr.utils.misc import get_device ImportError: cannot import name 'get_device' from 'basicsr.utils.misc' (D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\venv\lib\site-packages\basicsr\utils\misc.py)

Looking in indexes: http://mirrors.tools.huawei.com/pypi/simple ERROR: Ignored the following versions that require a different python version: 1.0 Requires-Python >=3.5, <3.8; 1.1 Requires-Python >=3.5, <3.8; 1.2 Requires-Python >=3.5, <3.8; 1.2.1 Requires-Python >=3.5, <3.8 ERROR: Could not find a version that satisfies the requirement facelib (from versions: none) ERROR: No matching distribution found for facelib

Steps to reproduce the problem

run webui.bat in windows

What should have happened?

Error setting up CodeFormer: Traceback (most recent call last): File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\modules\codeformer_model.py", line 38, in setup_model from facelib.utils.face_restoration_helper import FaceRestoreHelper File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\utils\face_restoration_helper.py", line 7, in from facelib.detection import init_detection_model File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\detection_init_.py", line 10, in from .retinaface.retinaface import RetinaFace File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\detection\retinaface\retinaface.py", line 14, in from basicsr.utils.misc import get_device ImportError: cannot import name 'get_device' from 'basicsr.utils.misc' (D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\venv\lib\site-packages\basicsr\utils\misc.py)

Commit where the problem happens

D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\modules\codeformer_model.py

What platforms do you use to access the UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

none

List of extensions

none

Console logs

Error setting up CodeFormer:
Traceback (most recent call last):
  File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\modules\codeformer_model.py", line 38, in setup_model
    from facelib.utils.face_restoration_helper import FaceRestoreHelper
  File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\utils\face_restoration_helper.py", line 7, in <module>
    from facelib.detection import init_detection_model
  File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\detection\__init__.py", line 10, in <module>
    from .retinaface.retinaface import RetinaFace
  File "D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\repositories\CodeFormer\facelib\detection\retinaface\retinaface.py", line 14, in <module>
    from basicsr.utils.misc import get_device
ImportError: cannot import name 'get_device' from 'basicsr.utils.misc' (D:\Tools\python\Stable-Diffusion-webui\stable-diffusion-webui-master\venv\lib\site-packages\basicsr\utils\misc.py)

Additional information

none

eric-hsu avatar Mar 30 '23 06:03 eric-hsu

Looking in indexes: http://mirrors.tools.huawei.com/pypi/simple

That Huawei package index your system is configured to use apparently doesn't contain all of the packages or versions thereof the regular PyPI does.

akx avatar Mar 30 '23 07:03 akx

This looks like a confusion call between:

  • the modified BasicSR directly referenced in CodeFormer Directory,
  • and the official BasicSR installed.

I tried to solve the problem temporarily by migrating get_device() to another location (exampli gratia: CodeFormerUtility.py) and modifying: from basicsr.utils.misc import get_device to the new location, to make CodeFormer load normally: from CodeFormerUtility import get_device

MetallicPickaxe avatar May 06 '23 17:05 MetallicPickaxe

This is how I solved it Copy the misc.py file from/repositories/CodeFormer/basicsr/utils Replace with the lib/site packages/basicsr/utils folder in the environment

ghost avatar Jul 16 '23 14:07 ghost

your idea works, i did this

replace the conda/envs/xxxxx/lib/python3.8/site-packages/basicsr-1.4.2-py3.8.egg/basicsr/utils/misc.py with stable-diffusion-webui/repositories/CodeFormer/basicsr/utils/misc.py

wangzhaolei avatar Aug 02 '23 05:08 wangzhaolei