Centos7安装Python3.6.2

1.环境

本文建立在Centos7环境下安装Python3.6.2

在终端输入

#python

Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

可知系统自带Python2.7.5版本,由与Python3使用成为一种趋势,因此需要安装Python3,由于系统部分文件运行依赖于Python,因此不建议卸载系统自带Python。

2.安装可能使用的依赖模块

#yum install openssl-devel bzip2-devel expat-devel gdbm-develreadline-devel sqlite-devel

3.下载Python3.6.2安装包

# wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

此操作,对于最小系统安装版或出现:

-bash:wget:command not found

即需要手动安装wget软件包,通过yum命令

#yum -y install wget

4.解压Python-3.6.2.tar.xz

先解压xz文件,再解压tar文件。

# xz -d Python-3.6.2.tar.xz

# tar xvf Python-3.6.2.tar

# cd Python-3.6.2

# ./configure --prefix=/usr/local

该部分操作,对于最小系统安装版会出现:

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details.

提示系统没有GCC编译器环境,因此

# yum -y install gcc

# make & make altinstall

5.更改/usr/bin/Python链接

#cd /usr/bin

#mv python python.backup   //备份python

#ln -s/usr/local/bin/python3.6 /usr/bin/python3 //建立软链接,通过Python3执行

6.启动Python3.6

#python3.6

启动Python3

#python2

启动Python2


猜你喜欢

转载自blog.csdn.net/qq_25062299/article/details/80076166
今日推荐