[Share Experiences] Deepin20.1安装Python3.9.1
Tofloor
poster avatar
xww5
deepin
2021-02-08 00:54
Author

0.首先在桌面运行运行命令端,输入如下:

python -V

可以看到系统内置python的版本,我的是2.7.6

为了以后操作方便,通过使用如下命令获取系统root权限

sudo su

输入命令后回车就会提示输入密码,输入完成后直接回车即可,命令端是不显示的。

 

 

1.安装编译所需要的组件

sudo apt update

sudo apt install make build-essential libssl-dev zlib1g-dev liblzma-dev

sudo apt install libbz2-dev libreadline-dev libsqlite3-dev llvm

sudo apt install libncurses5-dev libncursesw5-dev xz-utils tk-dev

 

2.下载最新版的Python源文件包编译安装

官网地址:https://www.python.org/

Python官网下载最新的安装包
https://www.python.org/downloads/

 

3.解压缩

tar -xvf Python-3.9.0.tgz

 

Deepin系统也可以直接鼠标右键,解压到当前文件夹,进入“Python-3.9.0”文件夹,右键打开终端(在终端中打开)

 

或者Cdpython解压目录

 

4.执行configure配置构件文件

sudo ./configure --enable-optimizations —with-ssl

 

5.编译

sudo make -j8

 

6.安装

sudo make altinstall

 

7.安装后的清理

sudo make clean

sudo apt autoremove

 

8.检查是否正常安装

sudo python3.9 -V

 

 

9.测试安装结果
终端(运行) sudo /usr/local/bin/python3.9

 

 

 10.建立软连接
终端(运行) sudo ln -s /usr/local/bin/python3.9 /usr/bin/python3.9
终端 输入python3.9就可以调用sudo python3.9

 

Reply Favorite View the author
All Replies
thepoy
deepin
2021-02-08 00:58
#1

为什么不用anaconda安装呢?

Reply View the author
xww5
deepin
2021-02-08 01:01
#2
thepoy

为什么不用anaconda安装呢?

也可以,我这里只是提供一下这种方法,让安装Python3的人多一个参考。

Reply View the author
sudo_free
deepin
2021-02-08 01:33
#3

为什么不用anaconda安装呢?+1

Reply View the author
SamLukeYes
deepin
2021-02-08 04:34
#4

有一说一,编译安装容易出问题,conda 真香

Reply View the author
kearney
deepin
2021-02-08 07:56
#5

有的包还没有完全适配py3.9.。。慎重

我比较好奇为什么linux大部分都带两个py2+3,删掉2会有什么影响嘛

Reply View the author
SamLukeYes
deepin
2021-02-08 08:36
#6
kearney

有的包还没有完全适配py3.9.。。慎重

我比较好奇为什么linux大部分都带两个py2+3,删掉2会有什么影响嘛

楼主用 altinstall 应该不会影响系统自带的 python。

Linux 发行版中的 python 是作为运行时的依赖而存在的,同时有 py2 和 py3 是因为 py2 和 py3 的区别比较大。虽然 py2 已经不维护了,但还是有一些维护不积极或者难以迁移的软件没有迁移到 py3,因此 Linux 发行版的仓库里通常会同时有这两个版本的 python。如果你的系统中还有重要的软件依赖 py2,就不能把 py2 删了。

Reply View the author
kearney
deepin
2021-02-08 20:20
#7
SamLukeYes

楼主用 altinstall 应该不会影响系统自带的 python。

Linux 发行版中的 python 是作为运行时的依赖而存在的,同时有 py2 和 py3 是因为 py2 和 py3 的区别比较大。虽然 py2 已经不维护了,但还是有一些维护不积极或者难以迁移的软件没有迁移到 py3,因此 Linux 发行版的仓库里通常会同时有这两个版本的 python。如果你的系统中还有重要的软件依赖 py2,就不能把 py2 删了。

不少新发行版都在开始去掉py2了,主要是一些后来下载的软件可能还是会依赖py2.。裂开

https://www.v2ex.com/t/582104

Reply View the author
SamLukeYes
deepin
2021-02-08 20:36
#8
kearney

不少新发行版都在开始去掉py2了,主要是一些后来下载的软件可能还是会依赖py2.。裂开

https://www.v2ex.com/t/582104

Arch 现在已经基本上迁移完毕了,官方仓库里除了 python2 的库以外只有很少的软件包依赖 python2 了

Reply View the author
xww5
deepin
2021-02-09 01:56
#9
kearney

有的包还没有完全适配py3.9.。。慎重

我比较好奇为什么linux大部分都带两个py2+3,删掉2会有什么影响嘛

这种方法不会删除Python2.只是把最新版的Python3安装到系统里面。对于一些应用,类似三维软件现在都是Python3有更好的支持。

Reply View the author
xww5
deepin
2021-02-09 01:57
#10
SamLukeYes

有一说一,编译安装容易出问题,conda 真香

还好,熟悉的话没啥问题,自己安装可能我个人感觉更可控吧。

Reply View the author
SamLukeYes
deepin
2021-02-09 03:31
#11
xww5

还好,熟悉的话没啥问题,自己安装可能我个人感觉更可控吧。

喜欢编译安装的话可以用 gentoo 哦

Reply View the author
zgy98
deepin
2021-02-20 21:44
#12

未安装之前可以试一下 python3  -V  看看是否安装了 python3

Reply View the author
huangzefang2012
deepin
2022-01-08 18:31
#13

sudo ./configure --enable-optimizations -with-ssl

原文with前面的符号错误直接复制会报错

Reply View the author
huangzefang2012
deepin
2022-01-08 19:02
#14

安装最后一步报错,只好切换默认版本用了3.7

ARNING: Value for scheme.headers does not match. Please report this to https://github.com/pypa/pip/issues/10151
distutils: /usr/local/include/python3.10/UNKNOWN
sysconfig: /home/huang/Downloads/Python-3.10.1/Python-3.10.1/Include/UNKNOWN
WARNING: Additional context:
user = False
home = None
root = '/'
prefix = None
Looking in links: /tmp/tmpo6fqz1hj
Processing /tmp/tmpo6fqz1hj/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpo6fqz1hj/pip-21.2.4-py3-none-any.whl
Installing collected packages: setuptools, pip
WARNING: Value for scheme.headers does not match. Please report this to https://github.com/pypa/pip/issues/10151
distutils: /usr/local/include/python3.10/setuptools
sysconfig: /home/huang/Downloads/Python-3.10.1/Python-3.10.1/Include/setuptools
WARNING: Value for scheme.headers does not match. Please report this to https://github.com/pypa/pip/issues/10151
distutils: /usr/local/include/python3.10/pip
sysconfig: /home/huang/Downloads/Python-3.10.1/Python-3.10.1/Include/pip
Successfully installed pip-21.2.4 setuptools-58.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv WARNING: Value for scheme.headers does not match. Please report this to https://github.com/pypa/pip/issues/10151
distutils: /usr/local/include/python3.10/UNKNOWN
sysconfig: /home/huang/Downloads/Python-3.10.1/Python-3.10.1/Include/UNKNOWN
WARNING: Additional context:
user = False
home = None
root = '/'
prefix = None
Looking in links: /tmp/tmpo6fqz1hj
Processing /tmp/tmpo6fqz1hj/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpo6fqz1hj/pip-21.2.4-py3-none-any.whl
Installing collected packages: setuptools, pip
WARNING: Value for scheme.headers does not match. Please report this to https://github.com/pypa/pip/issues/10151
distutils: /usr/local/include/python3.10/setuptools
sysconfig: /home/huang/Downloads/Python-3.10.1/Python-3.10.1/Include/setuptools
WARNING: Value for scheme.headers does not match. Please report this to https://github.com/pypa/pip/issues/10151
distutils: /usr/local/include/python3.10/pip
sysconfig: /home/huang/Downloads/Python-3.10.1/Python-3.10.1/Include/pip
Successfully installed pip-21.2.4 setuptools-58.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

Reply View the author