从www.python.org下载源码包
三步安装
./configure 或者./configure --enable-optimizations或者 ./configure --enable-optimizations --with-ssl --prefix=/usr
make
make install
make install碰到这个问题
ModuleNotFoundError: No module named ‘_ctypes’
需要安装依赖包
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
下面这个包也需要安装
yum install libffi-devel -y
yum install libffi -y
安装完这些软件包后,需要重新解压python源码包,然后重新configure make make install
再make install的时候发现/usr/local为只读文件系统,修改 Makefile,将里面的/usr/local 替换为/usr,就可以安装成功
make过程中报下面这个错
Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
这个是因为python3.7.3 需要openssl 1.0.2,而默认机器上安装的版本是1.0.1
参考这个帖子,安装openssl的新版本
http://www.lingdonge.com/daily/4176.html
wget http://www.openssl.org/source/openssl-1.0.2j.tar.gz
./config --prefix=/usr
make
make install
[root@linux1 Python-3.7.3]# openssl version
OpenSSL 1.0.2j 26 Sep 2016
然后重新./configure
make
make install
三步安装python3.7.3