Debian 11上安装Python 3.10,并切换系统默认Python版本

更新程序包并安装变异依赖环境

sudo apt update && sudo apt upgrade
sudo apt install wget build-essential libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

开始正式安装

1.下载Python源码包#
可以前往Python官网获取最新源码

cd ~
wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz

2.解压Python源码#
将下载好的源码包进行解压,默认放在当前文件夹下的压缩包同名文件夹内

tar xzf Python-3.10.0.tgz

3.编译Python源码#
进入解压后的文件夹内,进行选项配置

cd Python-3.10.0
./configure --enable-optimizations

--enable-optimizations为优化性能选项,其余类似的还有 --prefix=PATH 指定安装目录……,可根据需要进行选择。

默认安装路径为 /usr/local/bin

4.安装Python 3.10#

make altinstall

altinstall用于防止编译器覆盖默认Python版本

5.验证安装#
root:~ # python3.10

Python 3.10.0 (default, Dec  5 2021, 22:46:09) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

至此,已完成Python3.10的安装
接下来可以根据需要选择是否需要更改默认Python为Python3.10

切换Python版本#
可以使用以下两个命令 whereis或which 确定已安装python的版本和路径:

whereis:适用于查看目前已安装的所有Python版本及路径

root:~ # whereis python

python: /usr/bin/python2.7-config /usr/bin/python /usr/bin/python3.9 /usr/bin/python2.7 /usr/bin/python3.9-config /usr/lib/python3.9 /usr/lib/python2.7 /etc/python3.9 /etc/python2.7 /usr/local/bin/python3.10-config /usr/local/bin/python3.10 /usr/local/lib/python3.9 /usr/local/lib/python2.7 /usr/local/lib/python3.10 /usr/include/python3.9m /usr/include/python3.9 /usr/include/python2.7 /usr/share/man/man1/python.1.gz

which:适用于查看具体某个python版本的安装路径

[email protected]:~ # which python3.10
/usr/local/bin/python3.10
为单个用户切换Python版本#
只需要在该用户home目录下的 .bashrc 文件下新增 Alias 即可

alias python='/usr/local/bin/python3.10'

python具体版本和路径可根据个人需要确定

修改完毕后,使用source ~/.bashrc命令,重新加载 .bashrc 文件,使其生效

系统级切换Python版本#
使用update-alternatives --list python命令,为整个系统更改Python版本

1.列出所有可用Python替代版本#
root:~ # update-alternatives --list python

/usr/bin/python2.7
/usr/bin/python3.9
/usr/local/bin/python3.10

2.添加替代版本列表#
如果运行后出现错误信息:update-alternatives: error:no alternatives for python
则为没有更新替代版本列表,使用以下命令添加:

注意:update-alternatives --install

1.一般情况下,直接使用 /usr/bin/python 即可

2.即为需要更换的python

3.为需要添加的python版本的安装路径,可以在上文中确定

4.为优先级。数字越大,优先级越高

root:~ # update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: 使用 /usr/bin/python2.7 来在自动模式中提供 /usr/bin/python (python)
root:~ # update-alternatives --install /usr/bin/python python /usr/bin/python3.9 2
update-alternatives: 使用 /usr/bin/python3.9 来在自动模式中提供 /usr/bin/python (python)
root:~ # update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 3
update-alternatives: 使用 /usr/local/bin/python3.10 来在自动模式中提供 /usr/bin/python (python)
至此,系统已默认Python版本为3.10,验证如下:

root:~ # python

Python 3.10.0 (default, Dec  5 2021, 22:46:09) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

3.进行版本切换#
使用update-alternatives --config python命令即可

root:~ # update-alternatives --config python
有 3 个候选项可用于替换 python (提供 /usr/bin/python)。

  选择       路径                     优先级  状态
------------------------------------------------------------
* 0            /usr/local/bin/python3.10   3         自动模式
  1            /usr/bin/python2.7          1         手动模式
  2            /usr/bin/python3.9          2         手动模式
  3            /usr/local/bin/python3.10   3         手动模式

要维持当前值[*]请按,或者键入选择的编号:2
update-alternatives: 使用 /usr/bin/python3.9 来在手动模式中提供 /usr/bin/python (python)
root:~ # python

Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

文章来源于互联网:Debian 11上安装Python 3.10,并切换系统默认Python版本

已有 4919 条评论
  1. Williamcob

    active darknetmarkets orange sunshine pill

    Williamcob 回复
  2. DevinTug

    darknet drug trafficking deep web search engine url

    DevinTug 回复
  3. KaapLoF

    tor darknet best mdma vendor darknet market reddit

    KaapLoF 回复
  4. Johnnyapage

    darknet markets lsd-25 2023 dark markets hungary

    Johnnyapage 回复
  5. Jeromewrone

    best darknet market for weed buying drugs on the darknet

    Jeromewrone 回复
  6. HaaryStema

    Useful info. With thanks.
    pay someone to write my paper writing a research paper how to write a scientific paper research paper writer services

    HaaryStema 回复
  7. Andreyeduby

    Kudos, Ample information.
    custom research paper writing services research paper writer services term paper help proposal writing

    Andreyeduby 回复
  8. KaapLoF

    how to buy bitcoin and use on dark web https://dark-market-heineken.com/

    KaapLoF 回复
  9. KaaLoF

    darknet links 2023 drugs https://dark-market-heineken.com/

    KaaLoF 回复
  10. HaaryStema

    Very good information. Kudos.
    essay writter essay writer review write this essay for me write my paper for me

    HaaryStema 回复
  11. Andreyeduby

    Regards, Quite a lot of material.
    thesis creator thesis statements good thesis statements write a thesis

    Andreyeduby 回复
  12. BaaLoF

    best darknet markets for vendors https://dark-market-heineken.com/

    BaaLoF 回复
  13. HaaryStema

    Incredible a good deal of helpful information.
    writing a conclusion for an essay essay writing service review writing essays online writing an essay

    HaaryStema 回复
  14. Andreyeduby

    Thanks! Lots of material!
    phd dissertation dissertation def define dissertation dissertation uk

    Andreyeduby 回复
  15. BaaLoF

    what is a darknet drug market like berlin telegram group drugs

    BaaLoF 回复
  16. HaaryStema

    Regards, Lots of tips!
    buy dissertations writing a dissertation dissertation writing dissertation editing services

    HaaryStema 回复
  17. Andreyeduby

    Nicely put, Many thanks!
    pay for college papers college paper writing service paper writing service pay to write paper

    Andreyeduby 回复
  18. Brendonjar

    With thanks! Useful stuff.
    pay for an essay pay someone to write my college essay pay for essay reviews buy essay online
    help me write my essay essaytyper essaypro writing help
    custom writing plagiarism https://essayssolution.com

    Brendonjar 回复
  19. HaaryStema

    Helpful postings. Cheers!
    need help writing an essay medical school personal statement help with essay writing essay helper

    HaaryStema 回复
发表新评论