# rhel7安装python3
环境:rhel7.2
python版本号:Python 3.7.3
源码下载地址:https://www.python.org/downloads/release/python-373/
或者直接点此下载 https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
进入root用户,使用命令:
tar -xf Python-3.7.3.tgz
cd Python-3.7.3/
./configure 配置编译后,直接报错:
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.7... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/Python-3.7.3':
configure: error: no acceptable C compiler found in $PATH #在$ PATH中找不到可接受的C编译器See `config.log' for more details
所以安装先gcc,然后再配置编译
yum -y install gcc
./configure
完成后执行,补充一下:这里可以加上--enable-shared和-fPIC之后可以将python3的动态链接库编译出来,默认情况编译完lib下面只有python3.xm.a这样的文件,python本身可以正常使用,但是如果编译第三方库需要python接口的比如caffe等,则会报错;所以这里建议按照上面的方式配置,另外如果openssl不使用系统yum安装的,而是使用自己编译的比较新的版本可以使用--with-openssl=/usr/local/openssl这种方式指定,后面目录为openssl实际安装的目录,另外编译完还要将openssl的lib目录加入ld运行时目录中即可. --prefix=/usr/python用来指定安装路径。不指定的话默认路径在/usr/local/bin目录中,Python库安装在/usr/local/lib/pythonXX,XX为你使用的python的版本号。
然后编译源码,和安装
make&&make install
等待约3-5分钟后完成安装
验证:
python3 -V
Python 3.7.3
好了,现在就完成安装了
主要参考:https://www.cnblogs.com/freeweb/p/5181764.html