Python 是一种特别优秀的编程语言,截止目前,tiobe 编程语言排行榜 上 Python 已长时间稳居第一。Python 语言使用者大多采用 Anaconda 或 Miniconda,但这些集成安装包采用的并不是最新的 Python 3.11,据官网最新消息: Python 3.11 is between 10-60% faster than Python 3.10. On average, we measured a 1.25x speedup on the standard benchmark suite.. 为了能够使用最新最快的 Python 3.11,本篇介绍如何在 Ubuntu 18 上编译安装 Python.

官网下载安装包

官网地址:https://www.python.org/downloads/
Python 3.11: https://www.python.org/downloads/release/python-3110/

1
2
3
sudo apt update
sudo apt install wget
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tar.xz

编译安装

安装依赖包

1
2
sudo apt update
sudo apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

解压 python 二进制包并编译安装

1
2
3
4
5
6
7
8
9
10
# 安装路径
mkdir -p /usr/local/python
# 解压缩
tar -xvf Python-3.11.0.tar.xz
# 编译
cd Python-3.11.0
./configure --prefix=/usr/local/python
make
# 安装到上面的指定路径
make install

上面会把 python3.11 安装到 /usr/local/python

测试安装的 python 和 pip

1
2
/usr/local/python/bin/python3 --version
/usr/local/python/bin/pip3 --version

添加环境变量

1
2
3
echo 'PYTHON_HOME=/usr/local/python' >> ~/.bashrc
echo 'PATH=$PYTHON_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

参考文献

  1. Linux 下安装python3