安装python 2.7

安装包下载地址

windows:https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi
linux: https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz

Windows

1、运行安装程序,按提示进行安装
2、配置变量环境

此电脑-->属性-->高级系统设置-->高级-->环境变量--系统变量--选中Path-->编辑-->新建-->C:\Python27-->确定

验证:
PS C:\Windows\system32> python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print ('Hello World!!')
Hello World!!
>>> exit()
PS C:\Windows\system32>


Linux

CentOS 6 自带python 2.6,如没有可以yum安装
yum install python -y
以下是CentOS 6 编译安装python 2.7
#下载:
[root@Test Python-2.7.14]# wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz

#解压:
[root@Test Python-2.7.14]# tar zxvf Python-2.7.14.tgz -C /usr/local/src/

[root@Test Python-2.7.14]# cd /usr/local/src/Python-2.7.14/
[root@Test Python-2.7.14]# ls
aclocal.m4    configure     Doc      install-sh  Mac              Modules  PC             Python  setup.py
config.guess  configure.ac  Grammar  Lib         Makefile.pre.in  Objects  PCbuild        README  Tools
config.sub    Demo          Include  LICENSE     Misc             Parser   pyconfig.h.in  RISCOS

编译:
[root@Test Python-2.7.14]# ./configure --prefix=/usr/local

[root@Test Python-2.7.14]# make

[root@Test Python-2.7.14]# make install

验证:
[root@Test Python-2.7.14]# python2.7
Python 2.7.14 (default, Oct 16 2017, 07:14:34) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello world...')
hello world...
>>> exit()

替换系统默认phthon为2.7
方法一:
[root@Test Python-2.7.14]# which python2.7
/usr/local/bin/python2.7
[root@Test Python-2.7.14]# export PATH="/usr/local/bin:$PATH"
[root@Test Python-2.7.14]# echo $PATH
/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

###########################################################################################################
方法二:
[root@Test ~]# /usr/bin/python --version
Python 2.6.6
[root@Test ~]# /usr/local/bin/python --version
Python 2.7.14

[root@Test ~]# mv /usr/bin/python /usr/bin/python2.6
mv: overwrite `/usr/bin/python2.6'? y
[root@Test ~]# ln -s /usr/local/bin/python2.7 /usr/bin/python


验证:
[root@Test Python-2.7.14]# python
Python 2.7.14 (default, Oct 16 2017, 07:14:34) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

修复 yum 工具

yum 默认使用python 2.6

[root@Test ~]# which yum
/usr/bin/yum
[root@Test ~]# vim /usr/bin/yum
#修改 yum中的python 
将第一行  #!/usr/bin/python  改为 #!/usr/bin/python2.6
posted @ 2017-10-16 20:42  考鸡蛋  阅读(408)  评论(0编辑  收藏  举报