您好,登錄后才能下訂單哦!
這篇文章主要講解了“如何編寫Shell腳本實現(xiàn)CentOS 6.x系統(tǒng)升級Python到2.7版本”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“如何編寫Shell腳本實現(xiàn)CentOS 6.x系統(tǒng)升級Python到2.7版本”吧!
在CentOS 6.x上,默認(rèn)自帶的Python是2.6.x版本,這個版本的Python有點老了,比如“collections.OrderedDict”就是2.7才有的,而且著名的Python Web框架Django的新版(如:1.7)就不支持Python2.6,最低要求是2.7了。而一些公司或者共有云上的服務(wù)器就是使用CentOS6.x,所以也就有了升級Python到2.7的需求。
升級Python之前,需要先安裝一些工具和軟件庫,否則后面安裝Python或pip時可能出錯。
Python2.7通過源碼安裝,python可行執(zhí)行程序默認(rèn)是安裝在/usr/local/bin/,一般來在$PATH中,/usr/local/bin是優(yōu)先使用的(如果不是,需要自己設(shè)置一下PATH環(huán)境變量)。
在安裝完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腳本實現(xiàn)CentOS 6.x系統(tǒng)升級Python到2.7版本”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對如何編寫Shell腳本實現(xiàn)CentOS 6.x系統(tǒng)升級Python到2.7版本這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。