centos升级python_CentOS 6.x升级Python到2.7

在CentOS 6.x上,默认自带的Python是2.6.x版本,这个版本的Python有点老了,比如“collections.OrderedDict”就是2.7才有的,而且著名的Python Web框架Django的新版(如:1.7)就不支持Python2.6,最低要求是2.7了。而一些公司或者共有云上的服务器就是使用CentOS6.x,所以也就有了升级Python到2.7的需求。

升级Python之前,需要先安装一些工具和软件库,否则后面安装Python或pip时可能出错。

Python2.7通过源码安装,python可行执行程序默认是安装在/usr/local/bin/,一般来在$PATH中,/usr/local/bin是优先使用的(如果不是,需要自己设置一下PATH环境变量)。

在安装完python后,还需要安装easy_install和pip这两个最常用工具。

install-python27-on-centos6

Shell

#!/bin/bash

# a script to install python 2.7 on CentOS 6.x system.

# CentOS 6.x has python 2.6 by default, while some software (e.g. django1.7)

# need python 2.7.

# install some necessary tools & libs

echo "install some necessary tools & libs"

yum groupinstall "Development tools"

yum install openssl-devel zlib-devel ncurses-devel bzip2-devel readline-devel

yum install libtool-ltdl-devel sqlite-devel tk-devel tcl-devel

sleep 5

# download and install python

version='2.7.8'

python_url="https://www.python.org/ftp/python/$version/Python-${version}.tgz"

# check current python version

echo "before installation, your python version is: $(python -V &2>1)"

python -V 2>&1 | grep "$version"

if [ $? -eq 0 ]; then

echo "current version is the same as this installation."

echo "Quit as no need to install."

exit 0

fi

echo "download/build/install your python"

cd /tmp

wget --no-check-certificate $python_url

tar -zxf Python-${version}.tgz

cd Python-${version}

./configure

make -j 4

make install

sleep 5

echo "check your installed python"

python -V 2>&1 | grep "$version"

if [ $? -ne 0 ]; then

echo "python -V is not your installed version"

/usr/local/bin/python -V 2>&1 | grep "$version"

if [ $? -ne 0 ]; then

echo "installation failed. use '/usr/local/bin/python -V' to have a check"

fi

exit 1

fi

sleep 5

# install setuptools

echo "install setuptools"

wget --no-check-certificate https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

python ez_setup.py

# check easy_install version

easy_install --version

sleep 5

# install pip for the new python

echo "install pip for the new python"

easy_install pip

# check pip version

pip -V

echo "Finished. Well done!"

echo "If 'python -V' still shows the old version, you may need to re-login."

echo "And/or set /usr/local/bin in the front of your PATH environment variable."

echo "-------------------------"

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

#!/bin/bash

# a script to install python 2.7 on CentOS 6.x system.

# CentOS 6.x has python 2.6 by default, while some software (e.g. django1.7)

# need python 2.7.

# install some necessary tools & libs

echo"install some necessary tools & libs"

yumgroupinstall"Development tools"

yuminstallopenssl-develzlib-develncurses-develbzip2-develreadline-devel

yuminstalllibtool-ltdl-develsqlite-develtk-develtcl-devel

sleep5

# download and install python

version='2.7.8'

python_url="https://www.python.org/ftp/python/$version/Python-${version}.tgz"

# check current python version

echo"before installation, your python version is: $(python -V &2>1)"

python-V2>&1|grep"$version"

if[$?-eq0];then

echo"current version is the same as this installation."

echo"Quit as no need to install."

exit0

fi

echo"download/build/install your python"

cd/tmp

wget--no-check-certificate$python_url

tar-zxfPython-${version}.tgz

cdPython-${version}

./configure

make-j4

makeinstall

sleep5

echo"check your installed python"

python-V2>&1|grep"$version"

if[$?-ne0];then

echo"python -V is not your installed version"

/usr/local/bin/python-V2>&1|grep"$version"

if[$?-ne0];then

echo"installation failed. use '/usr/local/bin/python -V' to have a check"

fi

exit1

fi

sleep5

# install setuptools

echo"install setuptools"

wget--no-check-certificatehttps://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

pythonez_setup.py

# check easy_install version

easy_install--version

sleep5

# install pip for the new python

echo"install pip for the new python"

easy_installpip

# check pip version

pip-V

echo"Finished. Well done!"

echo"If 'python -V' still shows the old version, you may need to re-login."

echo"And/or set /usr/local/bin in the front of your PATH environment variable."

echo"-------------------------"

一篇参考文档:

https://github.com/h2oai/h2o/wiki/Installing-python-2.7-on-centos-6.3.-Follow-this-sequence-exactly-for-centos-machine-only

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值