码迷,mamicode.com
首页 > 编程语言 > 详细

Centos 7上安装Python3.x

时间:2017-11-07 19:37:06      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:centos   安装使用   exp   sql   方式   pre   zip2   python3   span   

Centos7默认安装的是2.7,这里选择安装使用Python3.6.3

安装Python3.6.3

1、安装python3 需要的依赖包

yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc cc

2、下载python源码

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

3、解压和编译

mkdir /usr/local/python3 -p
tar xf Python-3.6.3.tgz
cd Python-3.6.3
./configure --prefix=/usr/local/python3
make
make install

4、备份旧版python软链接,链接新版本python

[root@localhost ~]# ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 9 Oct 20 14:08 /usr/bin/python -> python2
[root@localhost ~]# ls -l /usr/bin/python2
lrwxrwxrwx. 1 root root 9 Oct 20 14:08 /usr/bin/python2 -> python2.7
[root@localhost ~]# ls -l /usr/bin/python2.7
-rwxr-xr-x. 1 root root 7136 Nov  5  2016 /usr/bin/python2.7

 

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

5、修改yum配置文件

vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down

将第一行指定的python版本改为python2.7(#!/usr/bin/python 改为 #!/usr/bin/python2.7)

6、检验 Python 及 pip 版本

[root@localhost ~]# python -V
Python 3.6.3
[root@localhost ~]# pip -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)

参考原文地址:http://mp.weixin.qq.com/s/9fluqSWaDwkyAUMYiXF8dw(提供了另一种共存方式)

Centos 7上安装Python3.x

标签:centos   安装使用   exp   sql   方式   pre   zip2   python3   span   

原文地址:http://www.cnblogs.com/jmaly/p/7800091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!