- 1 min

Linux 下安装 Python3.6

Table of Contents

Python3.6 安装

安装依赖

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

下载解压缩

1.官网下载所需 python3 的版本
 wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

2.解压
 tar -xf Python-3.6.1.tgz

3.进入目录
 cd Python-3.6.1/

编译安装

 ./configure --prefix=/usr/local/python3
 make
 make install

创建软链接

1.移除旧版本
 mv /usr/bin/python /usr/bin/python_bak

2.创建新版本
 ln -s /usr/local/python3/bin/python3 /usr/bin/python

检查版本号

 python -V

问题解决

系统默认版本切换成 py3 后会发生两个问题啦~ yum 和 pip3 无法使用,下面是解决方法

yum 报错解决

 报错:
 	[root@Topaz tools]# yum -y install xxx
 	File "/usr/bin/yum", line 30
 解决:
 	// shangbang指向py2.7
	[root@Topaz tools]# vim /usr/bin/yum
	#!/usr/bin/python2.7		

	// CentOS 7 /usr/libexec/urlgrabber-ext-down 也需要改
	[root@Topaz tools]# vim /usr/libexec/urlgrabber-ext-down
	#!/usr/bin/python2.7		

解决 pip3 不能使用

加软链指向 /usr/local/bin/

 ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3  
Topaz

Topaz

Always keep learning.

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo