💾 Archived View for darknesscode.xyz › notes › change-python-version.gmi captured on 2024-02-05 at 09:44:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-05)

-=-=-=-=-=-=-

Change Python Version

Debian is still delivered with 2.7 as the default version of python. /usr/bin/python is in fact a symlink to the current default versions binary.

The update-alternatives scripts allows to change this.

ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Nov 24  2017 /usr/bin/python -> python2.7

Check with versions are already installed

dpkg -l | grep python

The output will be something like this

...
ii  python2.7
...
ii  python3
...
ii  python3.5
...

Check what are the python versions in /usr/bin/

ls -l /usr/bin/python*

The output will be something like this

/usr/bin/python -> python2.7
/usr/bin/python2 -> python2.7
/usr/bin/python2.7
/usr/bin/python3 -> python3.5
/usr/bin/python3.5

Python 2.7 and 3.5 are installed. python3 is a symlink to 3.5

To set python 3.5 as default use the update-alternatives scripts. You can set more alternatives the last number defines the priority. Higher number means higher priority.

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

if you want to set python3.5 to be the priority change it to number 1

After setting more then one alternatives you can easily switch the version by running

update-alternatives --config python

You need sudo privilege to run the last commands.

----------

Home

Linux

Notes

MicroLog

----------

© DarknessCode