0%

Ubuntu从源码编译安装Python

事情源于我要给新装的Ubuntu安装Python3.10, 结果在官网居然没有发现安装包

找了半天反正没找到, 只有源码没有发行版

没辙, 从源码编译安装吧

安装依赖

1
2
apt update
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

下载对应版本的Python, 例如这里是3.10.8

1
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.8.tgz

解压

1
tar -xf Python-3.10.*.tgz

检查配置

1
2
cd Python-3.10.*/
./configure --enable-optimizations

编译

1
make -j $(nproc)

安装到/usr/bin/python

1
make altinstall

https://computingforgeeks.com/how-to-install-python-on-ubuntu-linux-system/