操作系统:centos7.6-1810-x86_64
python: 3.9.9
安装操作系统:
1. 选择Server with GUI
2. yum install epel-release
3. wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz #下载python3.9.9源代码(https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz)
4.wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.4.0/gcc-9.4.0.tar.xz
# centos 7.6自带的gcc是4.8.5 版本,若要优化编译python3.9.9,需要更高版本的gcc
#此处下载并编译9.4.0版本的gcc
5. yum install gcc gcc-c++ -y #安装4.8.5版本的gcc,用于编译9.4.0版本的gcc
6. tar xvf gcc-9.4.0.tar.xz
7. ./configure --prefix=/opt/gcc
7A yum install flex flex-devel -y
8. yum install gmp gmp-devel -y
9.yum install mpfr mpfr-devel -y
10. wget http://www.multiprecision.org/downloads/mpc-0.9.tar.gz
11. ./configure
12. make
13. make install
14./configure --prefix=/opt/gcc --enable-multilib
15. vi /etc/ld.so.conf # append /usr/local/lib/ to /etc/ld.so.conf
15A. ldconfig
16 yum install glibc-devel.i686 # gcc 同时支持64位和32位
17tar xvf Python-3.9.9.tgz
18 yum install openssl openssl-devel libffi-devel -y
19 yum install sqlite sqlite-devel -y
19A wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
19B ./config --prefix=/opt/openssl
19C ./make -j4 & make install
19D vi /etc/ld.so.conf. # append /opt/openssl/lib
20 ./configure --prefix=/opt/python3 --enable-shared --enable-optimizations
21. make -j4
22 make install
23 ln -s /opt/python3/bin/python3 /usr/bin/python3
24 ln -s /opt/python3/bin/pip3 /usr/bin/pip3
25 vi /etc/ld.so.conf #append /opt/python3/lib
26 ldconfig
27 python3 -m pip install --upgrade pip
everything is OK