rhel7安装python3

本文档详细介绍了在RHEL7.2环境下,如何从源码编译安装Python3.7.3。首先,由于缺少C编译器,需要通过yum安装gcc。接着,配置编译时可添加--enable-shared和-fPIC选项,以便生成动态链接库。如果使用自编译的openssl,可以使用--with-openssl参数指定路径。最后,执行make && make install完成安装,并通过python3 -V命令验证安装成功。

# 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值