BlafKing / sd-civitai-browser-plus

Extension to access CivitAI via WebUI: download, delete, scan for updates, list installed models, assign tags, and boost downloads with multi-threading.
GNU Affero General Public License v3.0
309 stars 53 forks source link

[Bug]: Python module 'packaging' has not been imported correctly #161

Closed Yaruze66 closed 9 months ago

Yaruze66 commented 9 months ago

Describe the bug.

When I launching SD-WebUI with this extension, I get the following this in the console: "CivitAI Browser+: Python module 'packaging' has not been imported correctly, please try to restart or install it manually."

  1. I tried restarting the SD-WebUI.
  2. I checked and made sure that the "packaging" module was installed.
  3. I reinstalled the module manually.

None of the above helped.

Steps to reproduce the problem.

  1. Go to SD-WebUI folder.
  2. Launch webui-user.bat.
  3. Get a warning in the console.

Expected behavior

Correct import of the Python "packaging" module.

System info

Console logs

venv "D:\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Launching Web UI with arguments: --theme dark --xformers
Updating OpenCV from version 4.8.1 to 4.8.1.78
Requirement already satisfied: opencv-python in c:\users\michael\appdata\local\programs\python\python310\lib\site-packages (4.9.0.80)
Requirement already satisfied: numpy>=1.17.0 in c:\users\michael\appdata\local\programs\python\python310\lib\site-packages (from opencv-python) (1.26.3)

[notice] A new release of pip available: 22.2.1 -> 23.3.2
[notice] To update, run: python.exe -m pip install --upgrade pip
Update complete.
CivitAI Browser+: Aria2 RPC started
CivitAI Browser+: Python module 'packaging' has not been imported correctly, please try to restart or install it manually.
Loading weights [6ce0161689] from D:\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 9.3s (prepare environment: 1.9s, import torch: 2.9s, import gradio: 0.7s, setup paths: 0.7s, initialize shared: 0.2s, other imports: 0.5s, setup codeformer: 0.1s, list SD models: 0.1s, load scripts: 1.6s, create ui: 0.4s, gradio launch: 0.2s).
Creating model from config: D:\stable-diffusion-webui\configs\v1-inference.yaml
Applying attention optimization: xformers... done.
Model loaded in 4.5s (load weights from disk: 2.0s, create model: 0.3s, apply weights to model: 1.8s, load VAE: 0.1s, calculate empty prompt: 0.1s).

Additional information

No response

BlafKing commented 9 months ago

I assume you installed the packaging module to a different python instance, since if it's installed, the error should not occur. You can try finding the python executable that gets used by SD-WebUI and directly install it into that instance.

Usually the python instance that gets used by SD-WebUI is next to the webui folder. image

You can then find the python executable in system/python/python.exe, if you open a cmd window in this python directory, you should be able to run python -m pip install packaging

You can also manually check if the packaging module exists, it should be in system\python\Lib\site-packages\packaging

Let me know if that helps! :)

Yaruze66 commented 9 months ago

I'm using the regular Stable Diffusion WebUI from AUTOMATIC1111with Python 3.10.6 separately installed, I don't have any "system" or "webui" folders.

I have a packaging module in stable-diffusion-webui\venv\Lib\site-packages (Requirement already satisfied: packaging in d:\stable-diffusion-webui\venv\lib\site-packages (23.2)).

I also tried installing this module in %localappdata%\Programs\Python\Python310\Lib\site-packages but it also didn't help.

BlafKing commented 9 months ago

I see, I don't see exactly know how it could fail to find the packaging module, I use the built in launch_utils of SD-WebUI to check it's existence.

If you'd like you can verify which exact python executable your SD-WebUI uses by doing the following.

In the directory that webui-user.bat is in, you can find the modules folder, inside here you have a file called launch_utils.py Open the file, and find the line with:

python = sys.executable

Below this, you can add a new line and write something like:

print(f"Python location: {python}")

This will then print the python location when you start SD-WebUI.

Yaruze66 commented 9 months ago

Python location: D:\stable-diffusion-webui\venv\Scripts\python.exe

If I delete the folders "packaging" and "packaging-23.2.dist-info" in D:\stable-diffusion-webui\venv\Lib\site-packages then I get the following log:

venv "D:\stable-diffusion-webui\venv\Scripts\Python.exe"
Python location: D:\stable-diffusion-webui\venv\Scripts\python.exe
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Traceback (most recent call last):
  File "D:\stable-diffusion-webui\launch.py", line 48, in <module>
    main()
  File "D:\stable-diffusion-webui\launch.py", line 39, in main
    prepare_environment()
  File "D:\stable-diffusion-webui\modules\launch_utils.py", line 396, in prepare_environment
    if not requirements_met(requirements_file):
  File "D:\stable-diffusion-webui\modules\launch_utils.py", line 283, in requirements_met
    import packaging.version
ModuleNotFoundError: No module named 'packaging'

Does this mean that the module is actually installed correctly, and in my case, for some reason, it is the extension cannot import it correctly?

BlafKing commented 9 months ago

I see now that the issue is caused by my extension after all, sorry for making you do all those checks 😅 You likely installed the packages module correctly so I made that error message quite confusing.

I simply made it print the Python module 'packaging' has not been imported correctly message whenever any error occured, rather than when an actual import error occured.

I will post a hotfix in a bit that should hopefully resolve the issue!

BlafKing commented 9 months ago

I've posted a quick hotfix which should now only print the import error message when an actual import error occurs.

It also tries an alternative way of fetching the SD-WebUI version if the initial method failed, please let me know if the latest commit fixes your issue! :)

Yaruze66 commented 9 months ago
CivitAI Browser+: Aria2 RPC started
*** Error loading script: civitai_gui.py
    Traceback (most recent call last):
      File "D:\stable-diffusion-webui\modules\scripts.py", line 382, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\stable-diffusion-webui\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 "D:\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_gui.py", line 34, in <module>
        ver_bool = version.parse(ver[1:]) >= version.parse("1.7")
      File "D:\stable-diffusion-webui\venv\lib\site-packages\packaging\version.py", line 54, in parse
        return Version(version)
      File "D:\stable-diffusion-webui\venv\lib\site-packages\packaging\version.py", line 200, in __init__
        raise InvalidVersion(f"Invalid version: '{version}'")
    packaging.version.InvalidVersion: Invalid version: '1.6.0-2-g4afaaf8a'
Yaruze66 commented 9 months ago

https://github.com/BlafKing/sd-civitai-browser-plus/issues/154 <- I noticed that someone here also has a non-standard version of SD-WebUI and has the same problem with importing the module. Can the non-standard writing of the version ("v1.6.0-2-g4afaaf8a" instead of simple "v1.6.0") somehow affect?

BlafKing commented 9 months ago

Good catch! That was indeed causing an error, I've published another commit which should fix that issue as well!

Yaruze66 commented 9 months ago

Nice! Problem fixed! Thank you! 😉

BlafKing commented 9 months ago

Awesome! I'll go ahead and close this bug report! :)