I recently had to update the python version on an embedded device running Python 3.6. This process seems like it should be straightforward. I should sudo-apt install python3.9
and an update should be installed. This, however, wasn’t the case for me.
My installation process was a winding path wherein the majority of the knowledge was acquired from a blog that is unassociated with python.org. A search of the site yields no results regarding updating on Linux.
The actual updating process
What I had to do:
# Upgrade Python
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt install python 3.9
$ python3.9 --version # verify the python installation
At this point it seems like you should be done. Python should work and it should be the most recent version but no…
# Upgrade pip
$ python -m pip install --upgrade pip
Are we done? Not quite
# Set python version
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 2
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 3
$ sudo update-alternatives --config python
Finally! We can (hopefully) now run python -v
and have an expected result. This process is a cobbled together verion of various stackoverflow and blog posts. What should have taken 15 minutes ended up taking an hour and a half. This points to poor documentation. In a perfect world python.org would provide this info. Hopefully we get there soon.