I'm using WSL how I upgrade Python to the last version through the console?
Right now I have 3.8.10
I tried these steps and it worked.
Note: in step 3 you just need to change the version that you want to install
Installation steps
Run the following commands in your WSL terminal:
# Update package lists{
sudo apt update
# Install dependent libraries:
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
# Download Python binary package:
wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz
# Unzip the package:
tar -xzf Python-3.10.8.tgz
# Execute configure script
cd Python-3.10.8
./configure --enable-optimizations
# Build Python 3.10
make -j 2
# Install Python 3.10
sudo make install
# Verify the installation
python3.10
You should see:
Python 3.10.8 (default, october 15 2022, 14:44:10)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
If you want to make Python 3.10 the default that runs when you type python
, you can follow these steps:
Change ~/.bashrc file to add the following line:
alias python='/usr/local/bin/python3.10'
And then run the following command to have it take effect in the current shell:
source ~/.bashrc
You can verify it using the python --version
command, which should now show:
Python 3.10.8
Originally found in this article.
I'm not sure if others are overthinking it, things have changed in WSL, or my distro (Debian) is well behaved?
I simply ran this, and Python3 went from 3.9 to 3.11:
sudo apt update
sudo apt upgrade
As others have said, due to the way Python changes, this may loose some backward compatibility, but if you're not worried about that this should be fine.
What may have also helped this run smoothly, is I have all of these repos defined:
deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://security.debian.org/debian-security/ bullseye-security main
deb http://ftp.debian.org/debian bullseye-backports main
deb http://ftp.debian.org/debian stable main contrib non-free
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With