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

Webui not working with Python 3.12 [Bug]: #15667

Open
3 of 6 tasks
Mackain opened this issue Apr 30, 2024 · 28 comments
Open
3 of 6 tasks

Webui not working with Python 3.12 [Bug]: #15667

Mackain opened this issue Apr 30, 2024 · 28 comments
Labels
bug-report Report of a bug, yet to be confirmed

Comments

@Mackain
Copy link

Mackain commented Apr 30, 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?

When running webui.sh you get an error that complains about torch. my understanding is that this is caused by later versions of Python not being compatible.

When you download python3 today you get 3.12. this is also the version of python that comes bundled with most OS installers (including archinstall, but I guess that depends on the choices you make during the installation process)

And, yes. The dependencies page does clearly state that it does specifically require 3.10.6. but downgrading Python is easier said than done. Most people have other things on their machine that require a later version of python, so downgrading python system-wide can potentially be dangerous and ruin your OS.

(There are also instructions on the NVIDIA page that you should install python3.10-venv. but that package does not exist anymore it seems... and you just get the error: E: Couldn't find any package by glob 'python3.10-venv')

Most people will not know how to set up miniconda or other tools to handle multiple versions of Python, so this has become a barrier that stops most people from using the webui now.

If it is not possible update the webui so that it works with a later version of python, then at least there needs to be clear and understandable instructions either in the README or the Dependencies that explains how to get around this issue. This cannot be hidden somewhere in a closed issue or a discussion thread but needs to be available and visible.

when I google this issue it becomes clear to me that this is an issue that has persisted for a while and has also popped up in previous versions of Python. so it seems to me that it would save everyone a lot of time and energy if clear instructions where given on how to deal with it (if it cannot simply be solved by updating the dependency)

in other words: I do not know if it is possible to fix the dependency, but if not then there at the documentation needs to be updated.

Steps to reproduce the problem

  1. fresh install of operating system (have tried Arch and Ubuntu 24.04)
  2. verify that python3 is installed as per Dependencies page
  3. follow installation steps as per the README
  4. Get the error shown below in the Console log.

What should have happened?

either webui should have just worked without the error OR clear instructions should have been given in the README on how to not end up in this situation.

What browsers do you use to access the UI ?

No response

Sysinfo

OS: Ubuntu 24.04 LTS x86_64
Kernel: 6.8.0-31-generic
Uptime: 9 mins
Packages: 1676 (dpkg), 10 (snap)
Shell: bash 5.2.21
Resolution: 2560x1080
DE: GNOME 46.0
WM: Mutter
WM Theme: Adwaita
Theme: Yaru-dark [GTK2/3]
Icons: Yaru [GTK2/3]
Terminal: gnome-terminal
CPU: Intel i9-9900K (16) @ 5.000GHz
GPU: NVIDIA GeForce RTX 2070 SUPER
Memory: 2210MiB / 48082MiB

(have also tried with arch running KDE on same machine)

Console logs

Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0]
Version: v1.9.3
Commit hash: 1c0a0c4c26f78c32095ebc7f8af82f5c04fca8c0
Installing torch and torchvision
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu121
ERROR: Could not find a version that satisfies the requirement torch==2.1.2 (from versions: 2.2.0, 2.2.0+cu121, 2.2.1, 2.2.1+cu121, 2.2.2, 2.2.2+cu121, 2.3.0, 2.3.0+cu121)
ERROR: No matching distribution found for torch==2.1.2

Additional information

No response

@Mackain Mackain added the bug-report Report of a bug, yet to be confirmed label Apr 30, 2024
@w-e-w
Copy link
Collaborator

w-e-w commented Apr 30, 2024

Most people have other things on their machine that require a later version of python, so downgrading python system-wide can potentially be dangerous and ruin your OS.

Most people will not know how to set up miniconda or other tools to handle multiple versions of Python, so this has become a barrier that stops most people from using the webui now.

it is quite common to install multiple versions of python without extra tools like miniconda

image
image

(There are also instructions on the NVIDIA page that you should install python3.10-venv. but that package does not exist anymore it seems... and you just get the error: E: Couldn't find any package by glob 'python3.10-venv')

I guess it depends on your distro, it's there on ubuntu
image

also 3.10 is still within support https://devguide.python.org/versions/

I believe it's only not working on python3.12 is because we use pytorch 2.1.2, python3.12 only comes in later versions
and even in 2.3.0 from last week https://github.com/pytorch/pytorch/releases/tag/v2.3.0

PyTorch support for Python 3.12 in general is considered experimental. Please use Python version between 3.8 and 3.11 instead. This is an existing issue since PyTorch 2.2


personally think it's better to wait about a year until switching to the newest stable python version otherwise I think it's just looking for trouble

@geodesius
Copy link

geodesius commented Apr 30, 2024

For Arch users who will have trouble going back to a previous version like me and come here:

If you try using pyenv to make SD use python 3.10.6 then it won't work (probably). I set the local python, global python and tried everything I can (within my limited knowledge) to make SD use 3.10. Even though python --version returned 3.10.6 running webui.sh started it with 3.12.

What you want to do (if you use "pyenv install 3.10.6") is edit webui-user.sh and set the path manually. Uncomment the second line below and input the path to your 3.10.6 version. Your path should be similar to mine:

# python3 executable
python_cmd="/home/$USER/.pyenv/versions/3.10.6/bin/python"

@Mackain
Copy link
Author

Mackain commented Apr 30, 2024

I guess it depends on your distro, it's there on ubuntu

not on ubuntu 24.03. This is what you get when you try to install it:

E: Couldn't find any package by glob 'python3.10-venv'
E: Couldn't find any package by regex 'python3.10-venv'

@HinaHyugaHime
Copy link
Contributor

For Arch users who will have trouble going back to a previous version like me and come here:

If you try using pyenv to make SD use python 3.10.6 then it won't work (probably). I set the local python, global python and tried everything I can (within my limited knowledge) to make SD use 3.10. Even though python --version returned 3.10.6 running webui.sh started it with 3.12.

What you want to do (if you use pyenv to install 3.10.6) is edit webui-user.sh and set the path manually. Uncomment the second line below and input the path to your 3.10.6 version. Your path should be similar to mine:

# python3 executable
python_cmd="/home/YOURUSERNAME/.pyenv/versions/3.10.6/bin/python"

or read my updated guide with building from source + swapping https://civitai.com/articles/1503

@HinaHyugaHime
Copy link
Contributor

HinaHyugaHime commented May 1, 2024

For Arch users who will have trouble going back to a previous version like me and come here:
If you try using pyenv to make SD use python 3.10.6 then it won't work (probably). I set the local python, global python and tried everything I can (within my limited knowledge) to make SD use 3.10. Even though python --version returned 3.10.6 running webui.sh started it with 3.12.
What you want to do (if you use pyenv to install 3.10.6) is edit webui-user.sh and set the path manually. Uncomment the second line below and input the path to your 3.10.6 version. Your path should be similar to mine:

# python3 executable
python_cmd="/home/YOURUSERNAME/.pyenv/versions/3.10.6/bin/python"

or read my updated guide with building from source + swapping https://civitai.com/articles/1503

had to update cause I ran into this issue yesterday and been working on figuring out a fix
edit: also you couldve pur /$USER/ instead of yourusername so people could copy it

@geodesius
Copy link

also you couldve pur /$USER/ instead of yourusername so people could copy it

Thank you, I didn't know that'd work. Edited according to your advice :)

@Mackain
Copy link
Author

Mackain commented May 1, 2024

personally think it's better to wait about a year until switching to the newest stable python version otherwise I think it's just looking for trouble

Okay, but the problem right now is that the new LTS version of Ubuntu comes bundled with 3.12 and has no straightforward way of allowing users to install 3.10

If making the webui work with 3.12 is a bad idea then the documentation needs to be updated to let Ubuntu 24.04 users know how to install it properly.

@w-e-w
Copy link
Collaborator

w-e-w commented May 1, 2024

no one is saying 3.12 is a bad idea
we are only saying webui is tested for 3.10
also torch's own release note says that support is experimental so there's no guarantee if we upgrade it will actually work
I assume eventually eventually we will move to 3.11 or 3.12 as the default but I don't think the time yet

3.12 support should come when we update torch

assuming that torch is the only thing that's causing issues

upgrading torch on its own is a really big change
lots of times stranger things break

if you wish to test new version of torch with to see if it works with python 3.12
you can set the environment variable TORCH_COMMAND to point to new verison before launching web UI

pip install torch==2.1.2 torchvision==0.16.2 --extra-index-url https://download.pytorch.org/whl/cu121"

remove the ==x.y.z version and it should install the newest version
specify specific version if you want to be specific

I think you also need the --reinstall-torch flag to tell webui to update, that or delete the venv and install everything a new

@HinaHyugaHime
Copy link
Contributor

personally think it's better to wait about a year until switching to the newest stable python version otherwise I think it's just looking for trouble

Okay, but the problem right now is that the new LTS version of Ubuntu comes bundled with 3.12 and has no straightforward way of allowing users to install 3.10

If making the webui work with 3.12 is a bad idea then the documentation needs to be updated to let Ubuntu 24.04 users know how to install it properly.

You could build from source like I mentioned, though you have to get dpkg and make before doing it, but its in my arch guide but you need to change pacman parts to apt

@Mackain
Copy link
Author

Mackain commented May 1, 2024

thank you all for the feedback. but it feels like I am not getting my point across.
yes, I see that there are several workarounds to getting this to work (I have not yet been successful but I am working on it)

but the problem is that those workarounds are not being documented anywhere that is easily accessible, and the existing documentation is misleading and not up to date.

I mean, sure, we can hope that people stumble across this ticket when they run into this problem in the future... but I feel like updating the documentation would help a lot of people and stop other tickets like this one from being created.

@httpjamesm
Copy link

httpjamesm commented May 1, 2024

Here's how I fixed it:

  1. source venv/bin/activate
  2. cd venv
  3. Change symlinks in bin/
    By default, the python, python3 binaries are actually just symlinks to /usr/bin/python3, which will be 3.12 in Ubuntu 24.04. Install version 3.10 and use ln -sf /path/to/new/3.10 python on both binaries.
  4. Ensure pip using python -m ensurepip
  5. Run webui.sh

@w-e-w
Copy link
Collaborator

w-e-w commented May 1, 2024

updating the documentation would help a lot of people and stop other tickets like this one from being created

like sure

if you or anyone can provide a better simple set of instructions that we can update that would be nice
the thing is there's just so many different flavors of linux with lots of minute differences, a good instruction for one may not be a construction for another
if we can verified to instructions to be better than the current one then there's no reason why we can't update the docs
I can update the wiki (at least the wiki which is easy to change)

btw we used to allow public editor of the wiki
but someone made the request about limieing the edie because of some hidden search engine rule that if the wiki is publicly editable then it doesn't show up on search engine or something similar and so it is now closed

@Koba0117
Copy link

Koba0117 commented May 2, 2024

I had the same problem but thanks to @httpjamesm , I finally can run sd natively! (I've been running it on podman for a while.)

Change symlinks in bin/
By default, the python, python3 binaries are actually just symlinks to /usr/bin/python3, which will be 3.12 in Ubuntu 24.04. Install version 3.10 and use ln -sf /path/to/new/3.10 python on both binaries.

As @Mackain said, updating the documentation probably helps a lot of people because newer linux distros use python3.12 as the default.
As far as I tested, changing symlinks of python binaries in venv worked for arch and fedora40 at least.

@HinaHyugaHime
Copy link
Contributor

updating the documentation would help a lot of people and stop other tickets like this one from being created

like sure

if you or anyone can provide a better simple set of instructions that we can update that would be nice
the thing is there's just so many different flavors of linux with lots of minute differences, a good instruction for one may not be a construction for another
if we can verified to instructions to be better than the current one then there's no reason why we can't update the docs
I can update the wiki (at least the wiki which is easy to change)

btw we used to allow public editor of the wiki
but someone made the request about limieing the edie because of some hidden search engine rule that if the wiki is publicly editable then it doesn't show up on search engine or something similar and so it is now closed

If the only issue is keeping python 3.10.6, I can provide a fix but you can still use latest, it just risks bugs here and there on linux distros being alot of packages depend on python

@w-e-w
Copy link
Collaborator

w-e-w commented May 2, 2024

I still don't really understand why installing a secondary version of python causes issues on Linux
as long as you don't change the default to the old version you should be fine right

@HinaHyugaHime
Copy link
Contributor

I still don't really understand why installing a secondary version of python causes issues on Linux
as long as you don't change the default to the old version you should be fine right

Its not installing a secondary version that is the problem, its swapping default, though now that you mention it, no issues on my end keeping 3.12 default so I'll check tomorrow and get back to you

@w-e-w
Copy link
Collaborator

w-e-w commented May 2, 2024

ya
like my screenshots
one can just python3.10 to use python 3.10, no need og changeing the default
venv also contains the libs

@HinaHyugaHime
Copy link
Contributor

ya
like my screenshots
one can just python3.10 to use python 3.10, no need og changeing the default
venv also contains the libs

Yeah I made a PR with changes lmk what think

@Mackain
Copy link
Author

Mackain commented May 2, 2024

I still don't really understand why installing a secondary version of python causes issues on Linux
as long as you don't change the default to the old version you should be fine right

The issue is that the version of python required seems to no longer be available trough apt/apt-get on Ubuntu 24.04. Or at least not trough the way described in the current documentation.

I would be happy to help write that documentation, but I will not have access to my computer for about 24h so I will get back on that one

@MariotteBoyle
Copy link

Here's how I fixed it:

  1. source venv/bin/activate
  2. cd venv
  3. Change symlinks in bin/
    By default, the python, python3 binaries are actually just symlinks to /usr/bin/python3, which will be 3.12 in Ubuntu 24.04. Install version 3.10 and use ln -sf /path/to/new/3.10 python on both binaries.
  4. Ensure pip using python -m ensurepip
  5. Run webui.sh

Hey hi, but I wonder, hot to "Install version 3.10", if the issue that we cannot install it.

@MariotteBoyle
Copy link

Here's how I fixed it:

  1. source venv/bin/activate
  2. cd venv
  3. Change symlinks in bin/
    By default, the python, python3 binaries are actually just symlinks to /usr/bin/python3, which will be 3.12 in Ubuntu 24.04. Install version 3.10 and use ln -sf /path/to/new/3.10 python on both binaries.
  4. Ensure pip using python -m ensurepip
  5. Run webui.sh

Hey hi, but I wonder, hot to "Install version 3.10", if the issue that we cannot install it.

Simply add python backports. It takes a simple search: https://kagi.com/search?q=ubuntu+24.04+install+python+3.10+backports+ppa&r=ca&sh=xJFqed72NAfJwB6PQ7-PxA

Nothing simple about all that and your solution. I cannot do it with a precise step by step guide. I guess I will install previous Ubuntu version.

@tincore
Copy link

tincore commented May 4, 2024

Similar to what @httpjamesm suggested.

To me is working fine (so far) with python 3.11 installed from deadsnakes ppa

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python-3.11-venv

And then just change the symlink at venv/bin/python3 to point to /usr/bin/python3.11

Also I upgraded all my A1111 plugins as I was getting another error because of one of them.

@HinaHyugaHime
Copy link
Contributor

Similar to what @httpjamesm suggested.

To me is working fine (so far) with python 3.11 installed from deadsnakes ppa

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python-3.11-venv

And then just change the symlink at venv/bin/python3 to point to /usr/bin/python3.11

Also I upgraded all my A1111 plugins as I was getting another error because of one of them.

Again, it works with any python version, just not all the functions will without it being 3.10.6, and the notification is mostly to get people on that version, if it prevents from starting, then it would be a issue, but you only need install 3.10.6

@BBCOT
Copy link

BBCOT commented May 8, 2024

What to do with this problem in Windows ?

ice_screenshot_20240508-061408

@MariotteBoyle
Copy link

What to do with this problem in Windows ?

ice_screenshot_20240508-061408

Not really sure but maybe trying to make the installation code with this https://pytorch.org/get-started/locally/

@BrettTree
Copy link

For Arch users who will have trouble going back to a previous version like me and come here:

If you try using pyenv to make SD use python 3.10.6 then it won't work (probably). I set the local python, global python and tried everything I can (within my limited knowledge) to make SD use 3.10. Even though python --version returned 3.10.6 running webui.sh started it with 3.12.

What you want to do (if you use "pyenv install 3.10.6") is edit webui-user.sh and set the path manually. Uncomment the second line below and input the path to your 3.10.6 version. Your path should be similar to mine:

# python3 executable
python_cmd="/home/$USER/.pyenv/versions/3.10.6/bin/python"

This is the fix. You are actually insanely huge. It actually says in the webui.sh file to edit the -user file and I just completely ignored it and stared dumbfounded as my shebangs to the pyenv environment didn't work. Never drop your crown king.

@Agreous
Copy link

Agreous commented May 22, 2024

for Archlinux: just install any AUR package manager(for me:yay) and install python310 package

@NXTler
Copy link

NXTler commented May 24, 2024

I switched to 3.10, but now I'm getting thi:

Installing torch and torchvision
/usr/bin/python3.10: No module named pip
Traceback (most recent call last):
  File "/run/media/tmpotratz/9fa0f123-fc70-4efe-a5c1-f928ce470f1e/stable-diffusion-webui/launch.py", line 48, in <module>
    main()
  File "/run/media/tmpotratz/9fa0f123-fc70-4efe-a5c1-f928ce470f1e/stable-diffusion-webui/launch.py", line 39, in main
    prepare_environment()
  File "/run/media/tmpotratz/9fa0f123-fc70-4efe-a5c1-f928ce470f1e/stable-diffusion-webui/modules/launch_utils.py", line 380, in prepare_environment
    run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
  File "/run/media/tmpotratz/9fa0f123-fc70-4efe-a5c1-f928ce470f1e/stable-diffusion-webui/modules/launch_utils.py", line 115, in run
    raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't install torch.
Command: "/usr/bin/python3.10" -m pip install torch==2.1.2 torchvision==0.16.2 --extra-index-url https://download.pytorch.org/whl/cu121
Error code: 1

pip is installed

EDIT:
Figured it out, just do /bin/python3.10 -m ensurepip --upgrade to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

No branches or pull requests