I'm using WSL how I upgrade Python to the last version through the console?
Right now I have 3.8.10
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
A couple of notes -- First, to quote @juanpa.arrivillaga's comment:
You don't "upgrade" python, you just get a new interpreter
The word "upgrade", of course, means to replace one version with a later/greater version. You don't want to do this. So, so, so many packages in most Linux distributions rely on Python, and these distributions are usually heavily tested against a particular Python release. You don't mention which Linux distribution you are using in WSL, but since Ubuntu is the default, we'll assume that. To see a list of all packages that are currently installed in Ubuntu that depend on Python, run:
apt-cache rdepends python3 | grep -v python | less
What you really want to do, most likely, is have access to a second (or third) Python version for a specific use. There are multiple ways to do this. I would suggest reading the answers on How do I install a different Python version using apt-get? on Ask Ubuntu. There are some good methods there as well. My solution is to use a Docker Python image -- There are images available for every currently support Python release (and some unsupported Python2 releases, even) there is.
© 2022 - 2024 — McMap. All rights reserved.