栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

ubuntu 中关于多版本python设置

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu 中关于多版本python设置

    安装依赖包
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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/747862.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号