到官网找到最新版本源码下载地址
https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
[[email protected] Downloads]# wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz [[email protected] 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
[[email protected] 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无法使用
[[email protected] ~]# yum File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax [[email protected]-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 [[email protected]-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:
恢复可用
时间: 2024-12-28 20:36:04