CentOS6编译安装Python3.7

准备编译环境

1
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel xz gcc-c++ gcc libffi-devel -y

下载并解压

1
2
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar xf Python-3.7.3.tar.xz -C /usr/local/src/

编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cd /usr/local/src/Python-3.7.3
./configure --prefix=/usr/local/python3 --with-ssl --enable-optimizations
make -j 4 && make install

最终提示如下,表示pip-9.0.1与setuptools-28.8.0同时安装成功
if test "x" != "x" ; then \
rm -f /usr/local/python3/bin/python3-32; \
(cd /usr/local/python3/bin; ln -s python3.7-32 python3-32) \
fi
rm -f /usr/local/python3/share/man/man1/python3.1
(cd /usr/local/python3/share/man/man1; ln -s python3.7.1 python3.1)
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpnffpnbr9
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0

建立软连接

1
2
ln -s /usr/local/python3/bin/python3.7 /usr/local/bin/python3 
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

升级到最新的pip

1
pip3 install --upgrade pip

修改默认的Python

1
2
3
4
5
mv /usr/bin/python /usr/bin/python_bak
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python

# 验证
python -V