广告
返回顶部
首页 > 资讯 > 后端开发 > Python >如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本
  • 393
分享到

如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本

2023-06-09 18:06:40 393人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

这篇文章主要讲解了“如何编写shell脚本实现Centos 6.x系统升级python到2.7版本”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何编写Shell脚本实现CentOS 6.x

这篇文章主要讲解了“如何编写shell脚本实现Centos 6.x系统升级python到2.7版本”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何编写Shell脚本实现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这两个最常用工具。

代码如下:

#!/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 $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 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 "-------------------------"

感谢各位的阅读,以上就是“如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本”的内容了,经过本文的学习后,相信大家对如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!

--结束END--

本文标题: 如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本

本文链接: https://www.lsjlt.com/news/257331.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本
    这篇文章主要讲解了“如何编写Shell脚本实现CentOS 6.x系统升级Python到2.7版本”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何编写Shell脚本实现CentOS 6.x...
    99+
    2023-06-09
  • CentOS 6.x系统升级Python到2.7版本的Shell脚本分享
    在CentOS 6.x上,默认自带的Python是2.6.x版本,这个版本的Python有点老了,比如“collections.OrderedDict”就是2.7才有的,而且著名的Python Web框架D...
    99+
    2022-06-04
    脚本 系统升级 版本
  • 如何编写Shell脚本实现温和方式重启Centos系统
    本篇内容介绍了“如何编写Shell脚本实现温和方式重启Centos系统”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!主要目的是用于重启后台比...
    99+
    2023-06-09
  • 如何编写Shell脚本实现系统时间和BIOS时间同步校准
    这篇文章主要介绍“如何编写Shell脚本实现系统时间和BIOS时间同步校准”,在日常操作中,相信很多人在如何编写Shell脚本实现系统时间和BIOS时间同步校准问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如...
    99+
    2023-06-09
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作