Install Python3.X on CentOS7

Published by davidliu on

CentOS7默认自带Python2.7版本,因为项目需要使用Python3.x,可以按照此文的方法进行安装。

1.Requirements

yum install gcc openssl-devel bzip2-devel libffi-devel

2.Download Python 3.7

cd /usr/srcwget

https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz

tar xzf Python-3.7.3.tgz

3.Install Python 3.7

cd Python-3.7.3

./configure –enable-optimizations

make altinstall

Note:make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

4.Check Python Version

python3.7 -V

备注:

1.如果要使用Python3.x作为python的默认版本 ,可以把用户自定义的配置放入/etc/profile.d/目录中,具体方法:

vi /etc/profile.d/python.sh

输入alias参数 alias python=’/usr/local/bin/python3.7’,保存退出。

使配置生效:source /etc/profile.d/python.sh

2.如果非root用户创建的文件需要注意设置权限:

chmod 755 /etc/profile.d/python.sh

Categories: Uncategorized

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *