> 文章列表 > ESP32学习二-更新Python版本(Ubuntu)

ESP32学习二-更新Python版本(Ubuntu)

ESP32学习二-更新Python版本(Ubuntu)

一、简介

        在一些场景里边,因为Python的版本过低,导致一些环境无法安装。这里来介绍以下,如何升级自己已安装的Python版本。例如如下情况:

二、实操

        1.查看本地版本

python --version

 

        2.添加源

sudo add-apt-repository ppa:jonathonf/python-3.7

         3.更新软件源

sudo apt-get update

         4.安装python 

sudo apt-get install python3.7

         5.调整Python3的优先级,使得3.7优先级较高

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

        此时再查看python的版本

        python3已经为3.7版本,但是python版本还是2.7。

        6.更改默认值,python默认为Python2,现在修改为Python3

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

        此时再查看python的版本。

        7.安装pip

sudo apt install python3-pip -y

        修改成功。