centos安装python2.7_CentOS6.x机器安装Python2.7.x

准备环境:CentOS6.9机器

1.查看机器默认的Python版本

[root@hlmcent69nma ~]# python -V

Python2.6.6[root@hlmcent69nma~]# whereispython

python:/usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python /usr/include/python2.6 /usr/share/man/man1/python.1.gz

2.安装gcc

[root@hlmcent69nma ~]# yum install gcc -y

3.下载最新的Python2.7.x安装包,解压并进入指定目录

[root@hlmcent69nma ~]# wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz

[root@hlmcent69nma ~]# ll Python-2.7.14.tgz-rw-r--r--. 1 root root 17176758 Sep 17 02:05 Python-2.7.14.tgz

[root@hlmcent69nma~]# tar zxvf Python-2.7.14.tgz

[root@hlmcent69nma~]# cd Python-2.7.14[root@hlmcent69nma Python-2.7.14]# ll

total1000

-rw-r--r--. 1 1000 1000 10914 Sep 17 01:38aclocal.m4-rwxr-xr-x. 1 1000 1000 44259 Sep 17 01:38config.guess-rwxr-xr-x. 1 1000 1000 36515 Sep 17 01:38config.sub-rwxr-xr-x. 1 1000 1000 442959 Sep 17 01:38configure-rw-r--r--. 1 1000 1000 141572 Sep 17 01:38configure.ac

drwxr-xr-x. 22 1000 1000 4096 Sep 17 01:38Demo

drwxr-xr-x. 18 1000 1000 4096 Sep 17 01:55Doc

drwxr-xr-x. 2 1000 1000 4096 Sep 17 01:38Grammar

drwxr-xr-x. 2 1000 1000 4096 Sep 17 01:38Include-rwxr-xr-x. 1 1000 1000 7122 Sep 17 01:38 install-shdrwxr-xr-x. 47 1000 1000 12288 Sep 17 01:38Lib-rw-r--r--. 1 1000 1000 12757 Sep 17 01:38LICENSE

drwxr-xr-x. 11 1000 1000 4096 Sep 17 01:38Mac-rw-r--r--. 1 1000 1000 48553 Sep 17 01:38 Makefile.pre.indrwxr-xr-x. 5 1000 1000 4096 Sep 17 01:38Misc

drwxr-xr-x. 9 1000 1000 4096 Sep 17 01:38Modules

drwxr-xr-x. 3 1000 1000 4096 Sep 17 01:38Objects

drwxr-xr-x. 2 1000 1000 4096 Sep 17 01:38Parser

drwxr-xr-x. 9 1000 1000 4096 Sep 17 01:38PC

drwxr-xr-x. 2 1000 1000 4096 Sep 17 01:38PCbuild-rw-r--r--. 1 1000 1000 35170 Sep 17 01:38 pyconfig.h.indrwxr-xr-x. 2 1000 1000 4096 Sep 17 01:38Python-rw-r--r--. 1 1000 1000 55670 Sep 17 01:38README

drwxr-xr-x. 5 1000 1000 4096 Sep 17 01:38RISCOS-rw-r--r--. 1 1000 1000 99231 Sep 17 01:38setup.py

drwxr-xr-x. 23 1000 1000 4096 Sep 17 01:38 Tools

4.配置,编译,编译安装

[root@hlmcent69nma Python-2.7.14]# ./configure --prefix=/usr/local/python/python2.7[root@hlmcent69nma Python-2.7.14]# make[root@hlmcent69nma Python-2.7.14]# make install

备注:

执行 ./configure --prefix=/usr/local/python/python3 命令。./configure命令执行完毕之后创建一个文件creating Makefile,供下面的make命令使用 执行make install之后就会把程序安装到我们指定的目录中去。Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure –help输出详细的选项列表。其中--prefix选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share,比较凌乱。如果配置--prefix,如:./configure --prefix=/usr/local/test可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。用了—prefix选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。当然要卸载程序,也可以在原来的make目录下用一次make uninstall,但前提是make文件指定过uninstall。

5.查看系统的Python版本,还是2.6.x

[root@hlmcent69nma ~]# python -V

Python2.6.6

6.查看新安装的Python版本,当前系统的Python版本,并将系统指向的Python从2.6.x修改为2.7.x,再次查看当前系统的Python版本,已经变更为2.7.x

[root@hlmcent69nma ~]# /usr/local/python/python2.7/bin/python2.7 -V

Python2.7.14[root@hlmcent69nma~]# /usr/bin/python -V

Python2.6.6[root@hlmcent69nma~]# mv /usr/bin/python /usr/bin/python.bak

[root@hlmcent69nma~]# ln -s /usr/local/python/python2.7/bin/python2.7 /usr/bin/python

[root@hlmcent69nma~]# python -V

Python2.7.14

7.但是发现yum命令无法使用了,由于yum是基于python2.6才能正常工作,需单独将yum指向python2.6版本

[root@hlmcent69nma ~]# yumlist

There was a problem importing one of the Python modules

required to runyum. The error leading to this problem was:

No module namedyumPleaseinstall a package whichprovides this module, or

verify that the module is installed correctly.

It's possible that the above module doesn't match the

current version of Python,whichis:2.7.14 (default, Nov 30 2017, 11:54:55)

[GCC4.4.7 20120313 (Red Hat 4.4.7-18)]

If you cannot solve this problem yourself, please go to

theyumfaq at:

http://yum.baseurl.org/wiki/Faq

[root@hlmcent69nma ~]# vim /usr/bin/yum

参考链接:

https://www.cnblogs.com/perallina/p/5253329.html

https://www.cnblogs.com/lclq/archive/2016/06/27/5620196.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值