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

CentOS安装python3.6

时间:2018-05-02 13:21:39      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:zip   efault   python安装   def   代码   compress   python   /usr   4.4   

下载Python安装包

cd /usr/local/src

编译时要提前装好gcc编译器和zlib zlib-devel

1、下载文件

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

2、解压

tar -zxvf Python-3.6.0.tgz

3、进入解压目录

cd Python-3.6.0

4、编译安装包

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

make && make install

5、添加环境变量

#echo PATH=‘/usr/local/python/bin/:$PATH‘ >> /etc/profile

#source /etc/profile

6、检查是否成功,执行下面代码

python3.6

Python 3.6.0 (default, Jun  1 2017, 14:01:43) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(‘hello word‘)
hello word

  

Python安装常见问题:

(1)configure: error: no acceptable C compiler found in $PATH

解决:yum install -y gcc

(2):zipimport.ZipImportError: can’t decompress data

解决:安装zlib zlib-devel

 

1、修改系统默认的Python路径,因为在终端中输入Python命令时默认是指向Python2.6.6

mv /usr/bin/python /usr/bin/python-2.6.6

  

2、建立新的软连接,指向Python-3.6.0  

 

ln -s /usr/local/python/bin/python3.6 /usr/bin/python

  

3、因为yum是依赖python的,所以这里我们修改了默认的python,就要要修改yum,让其运行指向旧的版本:

  vi /usr/bin/yum   

将第一行中的“#!/usr/bin/python”   修改为“#!/usr/bin/python-2.6.6”,保存即可

 

4、打开一个新的终端,通过python命令进入python环境,可以看到已经指向了我们新安装的python3.6.0:

 [centos65_1@localhost:~]$ python
Python 3.6.0 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

  

 

CentOS安装python3.6

标签:zip   efault   python安装   def   代码   compress   python   /usr   4.4   

原文地址:https://www.cnblogs.com/zuxing/p/8979303.html

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