- 安装依赖包
sudo apt-get update sudo apt-get install software-properties-common
- 添加 deadsnakes PPA 源
sudo add-apt-repository ppa:deadsnakes/ppa
- 安装 python 3.9
sudo apt-get update sudo apt-get install python3.9
- 配置 python3.9 为系统默认 python3
4.1 将 python 各版本添加到 update-alternatives
which python3.9 /usr/bin/python3.9 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 which python3.8 /usr/bin/python3.8 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
4.2 配置 python3 默认指向 python3.9
sudo update-alternatives --config python3 选择2回车
检查python版本
python3 --version
关于更改完python默认版本问题
如上所述,执行apt update 提示apt_pkg包不存在
解决方式
cd /usr/lib/python3/dist-packages ls -la /usr/lib/python3/dist-packages sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
If you get an error message saying too many levels of symbolic links as shown below:
cp: failed to access ‘/usr/lib/python3/dist-packages/apt_pkg.so’: Too many levels of symbolic links
Then you need to simply unlink the apt_pkg.so file. Use the following command:
sudo unlink apt_pkg.so
And then use the command
sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
关于执行add-apt-repository错误
解决方式是修改文件**/usr/bin/add-apt-repository**
Try editing the file /usr/bin/add-apt-repository and changing out the line #!/usr/bin/python3 with the specific version of python, in your case:
#!/usr/bin/python3.9
参考
https://os.51cto.com/article/681995.html
https://zhuanlan.zhihu.com/p/283041046



