Ubuntu 16安装Python 3.10

操作系统为Ubuntu 16.04,默认的Python版本有2.73.5。由于不满足要求,需要更高版本的python。这里使用了Python3.10。其他操作系统或不同版本,请参考使用

先安装 OpenSSL 1.1.1

系统默认的是1.0.2.g,不满足要求(可以在Python源码make 阶段看到相关错误)

$ wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz

$ tar -xzf openssl-1.1.1k.tar.gz

$ cd openssl-1.1.1k

$ ./config

$ make

$ sudo make install

sudo mv /usr/bin/openssl /usr/bin/openssl10.2
sudo ln -s /usr/local/bin/openssl /usr/bin/openssl

现在查看openssl版本:openssl version
openssl: error while loading shared libraries: libssl.so.1.1 cannot open shared object file: No such file or directory 
进入刚才解压得到的 openssl-1.1.0k 目录下,将动态链接库放到 /lib/x86_64-linux-gnu 执行 

cp libssl.so.1.1 /lib/x86_64-linux-gnu
cp libcrypto.so.1.1 /lib/x86_64-linux-gnu 

$ openssl version
OpenSSL 1.1.1k  25 Mar 2021

更新系统软件仓库:

$sudo apt-get update

安装必需的libffi等,视情况而定(可以在Python源码make 阶段看到相关错误)

$ sudo apt install libffi-dev libssl-dev

安装必要的编译工具

$ sudo apt-get install build-essential checkinstall

安装依赖库:

$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

从 Python 官网下载 Python 3.10 的源代码。通过如下命令下载:

$ wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz

$ tar -zxf Python-3.10.9.tgz

$ cd Python-3.10.9

$ ./configure

$ make

$ sudo make install

$ python3 –version

Python 3.10.9

$ pip3 –version

pip 22.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
 

为了在终端输入python时,使用安装的高版本python解释,需要将默认的解释器删除,并通过软链接新版的python解释器~
默认安装的python解释器在/usr/bin/python 或 /usr/bin/python3

$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       9 Nov 24  2017 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root       9 Nov 24  2017 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root     319 Feb 24  2016 /usr/bin/python2-jsonschema
-rwxr-xr-x 1 root root     151 Nov 23  2015 /usr/bin/python2-pbr
-rwxr-xr-x 1 root root 3492624 Mar  2  2021 /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 Oct 30 19:07 /usr/bin/python3 -> python3.5
-rwxr-xr-x 2 root root 4456208 Jan 27  2021 /usr/bin/python3.5
-rwxr-xr-x 2 root root 4456208 Jan 27  2021 /usr/bin/python3.5m
lrwxrwxrwx 1 root root      10 Oct 30 19:07 /usr/bin/python3m -> python3.5m

$ rm /usr/bin/python

$ ln -s /usr/local/bin/python3.10 /usr/bin/python

$python -V
Python 3.10.9

$ ln -s /usr/local/bin/pip3.10 /usr/bin/pip

$ pip -V
pip 22.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

你可能感兴趣的:(Python,ubuntu,linux,运维,python)