Install python 3.10 on Debian 11 WSL to replace default version

Question:

I would like to install Python 3.10.10 on my WSL Debian System. In particular I want to install it in the root usr/bin. The idea is that Debian uses python 3.10 as default python. Right now it uses 3.9.

What I tried was:

  1. install the required dependencies to be able to build Python 3.10 from the source.

     sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
    
  2. Then download Python 3.10 from the official Python release page.

    wget https://www.python.org/ftp/python/3.10.0/Python-3.10.10.tgz
    
  3. extract it as below

    tar -xf Python-3.10.*.tgz
    
  4. now run the configure command

    ./configure --enable-optimizations --prefix="/usr/bin"   
    
  5. finally I build python from that source

    make -j 4
    

It builds python just right, but builds it in the local bin (usr/local/bin).
Hence when I check:

 python3 -V

I get the old Python Version (3.9) instead of the new one used as default.
What am I doing wrong?

Tkx in advance

Asked By: aerioeus

||

Answers:

As stated, Python 3.9 is set as a default version in Debian 11.
After some research I found that one can set Python 3.10 as a default version using the following command:

update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
Answered By: aerioeus

One should not try to replace the system Python install in any Linux distribution: it will just take your system into an unusable state. For more than 10 years now, most Linux distributions rely on Python for critical system tasks, including package managing – and replacing the very files of the system Python packages will make all Python extensions in the system utilities to break at once.

The correct way to have various, and newer, Python versions in a Linux is to build them to other prefixes (even in the user home, no need for a global Python with other versions), and them leverage on virtaulenvs so that each project, or scratch directory for scripts one have, use the exact desired interpreter.

pyenvhttps://github.com/pyenv/pyenv – is the the "de facto" framework to have multiple Python versions in the same system.

That said, I reiterate, if you try to build your own Python and install it over the system’s one, you will break your system to re-install needed point. It looks like Debian provides a way to update the system Python version: but using an official package is another thing, as it will also update all other packages depending on Python, critical or not, in an atomic transaction.

Answered By: jsbueno