Skip to content

[Bug]: ImportError: cannot import name 'packaging' from 'pkg_resources' (/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py) #15863

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

Closed
3 of 6 tasks
roxas1212 opened this issue May 22, 2024 · 24 comments
Labels
bug Report of a confirmed bug bug-report Report of a bug, yet to be confirmed

Comments

@roxas1212
Copy link

roxas1212 commented May 22, 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?

Unable to start

Steps to reproduce the problem

run stable-diffusion

What should have happened?

stable-diffusion should be start

What browsers do you use to access the UI ?

Google Chrome

Sysinfo

--share --xformers --enable-insecure-extension-access --gradio-queue --no-half-vae --opt-channelslast --theme dark
xformers==0.0.20
torch==2.0.1+cu118
torchvision==0.15.2+cu118
torchaudio==2.0.2+cu118

Console logs

Python 3.10.14 (main, Apr  6 2024, 18:45:05) [GCC 9.4.0]
Version: v1.8.0
Commit hash: bef51aed032c0aaa5cfd80445bc4cf0d85b408b5
Launching Web UI with arguments: --share --xformers --enable-insecure-extension-access --gradio-queue --no-half-vae --opt-channelslast --theme dark
Traceback (most recent call last):
  File "/notebooks/stable-diffusion-webui/launch.py", line 48, in <module>
    main()
  File "/notebooks/stable-diffusion-webui/launch.py", line 44, in main
    start()
  File "/notebooks/stable-diffusion-webui/modules/launch_utils.py", line 465, in start
    import webui
  File "/notebooks/stable-diffusion-webui/webui.py", line 13, in <module>
    initialize.imports()
  File "/notebooks/stable-diffusion-webui/modules/initialize.py", line 39, in imports
    from modules import processing, gradio_extensons, ui  # noqa: F401
  File "/notebooks/stable-diffusion-webui/modules/processing.py", line 18, in <module>
    import modules.sd_hijack
  File "/notebooks/stable-diffusion-webui/modules/sd_hijack.py", line 5, in <module>
    from modules import devices, sd_hijack_optimizations, shared, script_callbacks, errors, sd_unet, patches
  File "/notebooks/stable-diffusion-webui/modules/sd_hijack_optimizations.py", line 13, in <module>
    from modules.hypernetworks import hypernetwork
  File "/notebooks/stable-diffusion-webui/modules/hypernetworks/hypernetwork.py", line 13, in <module>
    from modules import devices, sd_models, shared, sd_samplers, hashes, sd_hijack_checkpoint, errors
  File "/notebooks/stable-diffusion-webui/modules/sd_samplers.py", line 1, in <module>
    from modules import sd_samplers_kdiffusion, sd_samplers_timesteps, sd_samplers_lcm, shared
  File "/notebooks/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py", line 3, in <module>
    import k_diffusion.sampling
  File "/notebooks/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/__init__.py", line 1, in <module>
    from . import augmentation, config, evaluation, external, gns, layers, models, sampling, utils
  File "/notebooks/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/evaluation.py", line 6, in <module>
    import clip
  File "/usr/local/lib/python3.10/dist-packages/clip/__init__.py", line 1, in <module>
    from .clip import *
  File "/usr/local/lib/python3.10/dist-packages/clip/clip.py", line 6, in <module>
    from pkg_resources import packaging
ImportError: cannot import name 'packaging' from 'pkg_resources' (/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py)

Additional information

I use paperspace, I hope can provide a solution for paperspace, thank you

@roxas1212 roxas1212 added the bug-report Report of a bug, yet to be confirmed label May 22, 2024
@roxas1212 roxas1212 changed the title [Bug]: [Bug]: ImportError: cannot import name 'packaging' from 'pkg_resources' (/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py) May 22, 2024
@Bing-su
Copy link
Contributor

Bing-su commented May 22, 2024

Occurs when setuptools version is 70.0.0.

@Bewinxed
Copy link

Occurs when setuptools version is 70.0.0.

Confirmed, When I downgrade setuptools to <70, it works again.

@roxas1212
Copy link
Author

Occurs when setuptools version is 70.0.0.

Confirmed, When I downgrade setuptools to <70, it works again.

Could it be possible to elaborate on how this should be done?

@joel122002
Copy link

pip install

Occurs when setuptools version is 70.0.0.

Confirmed, When I downgrade setuptools to <70, it works again.

Could it be possible to elaborate on how this should be done?

python -m pip install setuptools==69.5.1

@garf23
Copy link

garf23 commented May 22, 2024

pip install

Occurs when setuptools version is 70.0.0.

Confirmed, When I downgrade setuptools to <70, it works again.

Could it be possible to elaborate on how this should be done?

python -m pip install setuptools==69.5.1

Issue still persists for me after downgrading. Any ideas?

@Bing-su
Copy link
Contributor

Bing-su commented May 23, 2024

assume your python venv folder name is venv

windows

.\venv\Scripts\Python.exe -m pip install "setuptools<70"

mac, linux

venv/bin/python -m pip install "setuptools<70"

@roxas1212
Copy link
Author

It works. Thank you so much both!

@Bewinxed
Copy link

Bewinxed commented May 23, 2024 via email

@abhishekmishra
Copy link

abhishekmishra commented May 23, 2024

If you're using the first windows install method, then python is installed by webui under sd.webui/system/python. I downgraded setuptools with the command below and then run.bat worked for me...

PS D:\ai\sd.webui\system\python> .\python.exe -m pip install setuptools==69.5.1

edit: update the path for your installation in the command above

@joel122002
Copy link

pip install

Occurs when setuptools version is 70.0.0.

Confirmed, When I downgrade setuptools to <70, it works again.

Could it be possible to elaborate on how this should be done?

python -m pip install setuptools==69.5.1

Issue still persists for me after downgrading. Any ideas?

Make sure you are using the right python command

Do this by writing
where python

This will show you where your python is located. You want to be downgrading setuptools for the python in your stable diffusion environment

To do that locate python in the sd.webui folder
sd.webui > system > python

image

Now type cmd here and enter
image

Finally write
python -m pip install setuptools==69.5.1

@CharlesRiggins
Copy link

It works. Thank you guys. Downgrading setuptools to version 69 resolved the issue. The reason I failed on the first try was due to my project setup, which automatically re-installed the latest (version 70) setuptools during the build process. After I disabled this automatic installation, the error no longer occurred.

@brothers132cv
Copy link

assume your python venv folder name is venv

windows

.\venv\Scripts\Python.exe -m pip install "setuptools<70"

mac, linux

venv/bin/python -m pip install "setuptools<70"

Just rename my folder "env" to "venv" then it works! Thank you so much!

@MikeyGea
Copy link

MikeyGea commented May 23, 2024

I am also seeing this error. Local and global setuptools rolled back to 69.5.1 and 68x don't make a difference for me. Is there not a way to roll back to a previous build of easydiffusion? Ubuntu x64 Haswell i5 w 3060 12GB

@Dqdopop313
Copy link

Hey there! I am very new to all of this and I have installed SD on my desktop and it does work, but I also wanted to install the Stability Matrix and I get this error from above *ImportError: cannot import name 'packaging' from 'pkg_resources'". The thing is that I have 3 versions of python when I write "where python" and none of them look like the screenshot from @joel122002. Can I have both a normal Automatic1111 SD installed and Stability Matrix? Where should I downgrade the tools (which folder) etc. Any help would be greatly appreciated, real newbie here. Thank you!

@joel122002
Copy link

joel122002 commented May 24, 2024

Steps on windows for beginners

Step 1:
image

Step 2:
image

Step 3:
image

Step 4:
image

Now run.bat should work

@Nelguz
Copy link

Nelguz commented May 25, 2024

-m : The term '-m' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • -m pip install setuptools==69.5.1

Steps on windows for beginners

Step 1: image

Step 2: image

Step 3: image

Step 4: image

Now run.bat should work

-m : The term '-m' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • -m pip install setuptools==69.5.1

@joel122002
Copy link

.\python -m !!!!!!!

  • -m pip install setuptools==69.5.1

commands are
cd .\system\python\
.\python -m pip install setuptools==69.5.1

@PrimeTimeTran
Copy link

What version of Python you running on your host machine? I think it doesn't matter but I'm unsure. Often times apps get updated but docs don't.

I ran into the same error running python 3.11.9 on my host machine. However when I run the update & run bat files I notice the terminal/logs print 3.10.6 so thats why I'm inclined to believe the project specified version takes precedence?

I do get error messages exactly like another issue though(however they're not fatal).

no module 'xformers'. Processing without...

Anyway a few seconds later, I run into this error which stops the bat file.

Thanks for answering in advance(your host machine python version).

@PrimeTimeTran
Copy link

PrimeTimeTran commented May 26, 2024

Steps on windows for beginners

Step 1:
....
Now run.bat should work

This solution worked for me. Thanks for sharing!

@Dqdopop313
Copy link

Steps on windows for beginners

Step 1: image

Step 2: image

Step 3: image

Step 4: image

Now run.bat should work

Hey and thanks for the reply! I am still very lost since I am trying to install this on Stability Matrix which is located at "C:\Users---\AppData\Roaming\StabilityMatrix\Packages\Stable Diffusion WebUI" as far as I can tell. And I am not sure if I should run the cmd here or somewhere esle? Thanks!

@Duodecimus
Copy link

You can also just find clip.py and fix the incorrect line.
from pkg_resources import packaging
can be changed to
import packaging

I have yet to see any bugs caused by this

@Hercule159753
Copy link

Steps on windows for beginners

Step 1: image

Step 2: image

Step 3: image

Step 4: image

Now run.bat should work

Thank you so much

@nachosupreme01
Copy link

Hey guys/gals wave i am a total noob (using windows 10 64 bit) so take this with a grain of salt, but i had exact same issue and i found a workaround installing python 3.10 via microsoft store (i had installed newest python from an exe earlier with no positive result). I had to run webui-user.bat though instead of run.bat . It was my quick fix, still working on the run.bat issue, hoping this helps anyone new to this similar to myself. Again i am a total noob, please forgive me. Best of luck

@w-e-w
Copy link
Collaborator

w-e-w commented May 28, 2024

fix has bee pushed to 1.9.4 so update to make it work

YaoYinYing added a commit to YaoYinYing/LigandMPNN that referenced this issue Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Report of a confirmed bug bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

No branches or pull requests