您的位置:首页 > 运维架构 > Linux

centos6安装python3

2015-12-30 22:14 525 查看
到官网找到最新版本源码下载地址

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

[root@lxy-zabbix Downloads]# wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz [root@lxy-zabbix Downloads]# tar zxvf Python-3.5.1.tgz
cd Python-3.5.1
./configure --prefix=/usr/local/python3
make
make install

Installing collected packages: setuptools, pip
Successfully installed pip-7.1.2 setuptools-18.2


修改旧的python链接

mv /usr/bin/python /usr/bin/python_old


建立链接

ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip


运行python

[root@lxy-zabbix Python-3.5.1]# python
Python 3.5.1 (default, Dec 25 2015, 21:48:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>


由于centos的yum依赖python2.6,这样一来yum无法使用

[root@lxy-zabbix ~]# yum
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax

[root@lxy-zabbix ~]# ll /usr/bin | grep python
-rwxr-xr-x.   1 root root       11016 1月  24 2013 abrt-action-analyze-python
lrwxrwxrwx    1 root root          24 12月 25 21:53 python -> /opt/python3/bin/python3
lrwxrwxrwx.   1 root root           6 11月 14 07:12 python2 -> python
-rwxr-xr-x.   2 root root        9032 10月 13 2012 python2.6
-rwxr-xr-x.   1 root root        1418 10月 13 2012 python2.6-config
lrwxrwxrwx.   1 root root          16 11月 14 07:12 python-config -> python2.6-config
-rwxr-xr-x.   2 root root        9032 10月 13 2012 python_old


修改yum的配置文件将#!/usr/bin/python改为#!/usr/bin/python2.6

vim /usr/bin/yum
[root@lxy-zabbix ~]# yum
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
You need to give some command
Usage: yum [options] COMMAND

List of Commands:


恢复可用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: