美文网首页
ubuntu安装python3.10并设置默认

ubuntu安装python3.10并设置默认

作者: 悠远晴空 | 来源:发表于2022-05-02 18:19 被阅读0次

    安装新版python:

    sudo apt update && sudo apt upgrade -y

    sudo apt install software-properties-common -y

    sudo add-apt-repository ppa:deadsnakes/ppa

    sudo apt install python3.10

    验证版本

    python3.10 --version

    ## 设置Python3.10 默认

    $ python3 --version

    Python 3.6.9

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

    update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode

    python3.10 --version

    Python 3.10.4

    $ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2

    update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode

    $ sudo update-alternatives --config python3

    There are 2 choices for the alternative python3 (providing /usr/bin/python3).

      Selection    Path                Priority  Status

    ------------------------------------------------------------

    * 0            /usr/bin/python3.10  2        auto mode

      1            /usr/bin/python3.10  2        manual mode

      2            /usr/bin/python3.6    1        manual mode

    Press <enter> to keep the current choice[*], or type selection number: 1

    安装pip3

    python3.10版本pip3貌似有问题,我降到3.9了。

    出现问题:

    ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)

    sudo apt install python3.9-distutils

    sudo add-apt-repository

    添加仓库出现错误:

    ModuleNotFoundError: No module named 'apt_pkg'

    修改:

    /usr/bin/add-apt-repository 中文件头指向原始python版本

    如:#!/usr/bin/python3.6

    相关文章

      网友评论

          本文标题:ubuntu安装python3.10并设置默认

          本文链接:https://www.haomeiwen.com/subject/hcjvyrtx.html