源码安装python

安装依赖

centos

1
yum install @development zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel findutils -y

如果提示openssl版本低,解决办法

1
2
3
4
5
6
7
8
9
10
11
wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -xf openssl-1.1.1k.tar.gz
cd openssl-1.1.1k
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared
make
make install
sh -c 'echo "/usr/local/ssl/lib" >> /etc/ld.so.conf.d/openssl.conf'
ldconfig

# 编译时添加--with-openssl参数
./configure --prefix=/usr/local/python3.10.11 --with-openssl=/usr/local/ssl

ubuntu

1
2
3
4
sudo apt-get install -y build-essential libncursesw5-dev libgdbm-dev libc6-dev \
zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev \
libxpm-dev libxext-dev libbz2-dev libssl-dev \
libncurses5-dev libsqlite3-dev

编译安装

1
2
3
4
5
6
sudo ./configure --prefix=/usr/local/python3.10.11
sudo make
sudo make test
sudo make install