站点图标 moneyslow.com

Ubuntu22.04下如何用源代码安装python3

如何安装python3

如何安装python3

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

在官网找到自己想要安装的版本:
https://www.python.org/downloads/source/

下载:
wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz

解压安装:
tar -xf Python-3.11.3.tgz
cd Python-3.11.3
./configure --enable-optimizations

参数介绍:
The --enable-optimizations option optimizes the Python binary by running multiple tests. This makes the build process slower.

根据自己服务器cpu的核数进行make,我的是12
make -j 12
make altinstall

为什么用altinstall ?
We’re using altinstall instead of install because the later command will overwrite the default system python3 binary.

验证:
python3.11 --version

退出移动版