wsl升级python3版本

Posted by 婷 on March 9, 2025 本文总阅读量

简介

介绍wsl怎么升级系统原生自动的python3版本,从python3.8.10python3.10

升级python3

原始的系统版本是3.8.10

image-20250302164656253

sudo add-apt-repository ppa:deadsnakes/ppa 

添加apt

image-20250302164308608

选择敲回车键

image-20250302164320010

image-20250302164337757

更新一下

sudo apt update

image-20250302164600166

查看是否有python3.10,这个是我们即将要升级的版本,选择安装

apt list | grep python3.10
sudo apt install python3.10

image-20250302164737993

安装了之后,因为系统中存在两个版本,所以我们要设置默认的版本为python3.10

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
sudo update-alternatives --config python3

image-20250302165032641

这时候如果用pip命令来安装依赖,还是会报错,需要执行以下命令来修复

sudo apt remove --purge python3-apt
sudo apt autoclean
sudo apt install python3-apt
sudo apt install python3.10-distutils

image-20250302165119425

image-20250302165152989

image-20250302165226559

image-20250302165258094

下载get-pip.py并安装,即可解决pip的问题

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.10 get-pip.py

image-20250302165338277

image-20250302201030511

参考链接