How can I force Ubuntu to upgrade Python?

95 views Asked by At

I'm trying to run Stable Diffusion and keep getting errors due to running python3.8.18 when I need to run at least python3.9 but nothing I do changes my python version.

I've tried using Conda, my package manager, exporting the path of the higher version, uninstalling Python, uninstalling python3, upgrading, and force updating. Nothing works. I always get Python 3.8.18 when I run python --version.

I have the Deadsnakes repo and still can't use it without invoking it directly. It still has the same output when I check the version, even in a new environment.

2

There are 2 answers

0
Bsonen Manoont Effectery On

Im guessing from your post you tried:

sudo apt install software-properties-common

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt update
sudo apt install python3.9

If this doesn't work: i would try

sudo update-alternatives --list python3

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1

sudo update-alternatives --config python3

and then click python 3.9

0
David Waterworth On

I would suggest you use pyenv to install the specific version of python you need, then create a virtual environment using the python version for each project. This both prevents you from breaking yuour system python (that may be used by other packages) and allows you to work on different projects that may have conflicting requirements.

Full instructions for installing can be found at https://github.com/pyenv/pyenv

One of the options is:

curl https://pyenv.run | bash`

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Then to install the version you need

pyenv install 3.9.17

Then you need to create a virtual env for you project

cd projects/myproject

pyenv local 3.9.17
python -m venv .venv
source .venv/bin/activate

Now when you type python --version it should be the version you need.