In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to write a Shell script to upgrade CentOS 6.x system Python to version 2.7". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to write a Shell script to upgrade CentOS 6.x system Python to version 2.7".
On CentOS 6.x, the default built-in Python is version 2.6.x, which is a bit old, such as "collections.OrderedDict" is 2.7, and the new version of the famous Python Web framework Django (e.g. 1.7) does not support Python2.6, with a minimum requirement of 2.7. Some companies or shared cloud servers use CentOS6.x, so there is a need to upgrade Python to 2.7.
Before upgrading Python, you need to install some tools and software libraries, otherwise you may make errors when installing Python or pip later.
Python2.7 is installed through source code, and the python feasible executor is installed in / usr/local/bin/, by default in $PATH, and / usr/local/bin is preferred (if not, you need to set the PATH environment variable yourself).
After installing python, you also need to install easy_install and pip, the two most commonly used tools.
The code is as follows:
#! / 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 "-"
Thank you for your reading, the above is "how to write Shell script to achieve CentOS 6.x system upgrade Python to version 2.7" content, after the study of this article, I believe you on how to write Shell script to achieve CentOS 6.x system upgrade Python to 2.7 version of this problem has a deeper understanding, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.