首頁 > 軟體

CentOS 6.5 指令碼自動化裝 Python2.6升級2.7

2020-06-16 17:21:48

前提:

CentOS 6.5現有的yum源, 並且能通網

指令碼會自動安裝Python2.7.8  、 pip 、 easy 、setuptools

正文:

程式碼內容

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

下面關於Python的文章您也可能喜歡,不妨參考下:

《Python核心程式設計 第二版》.(Wesley J. Chun ).[高清PDF中文版] 下載見 http://www.linuxidc.com/Linux/2013-06/85425.htm?1457061350967

零基礎如何入門Python http://www.linuxidc.com/Linux/2016-10/136485.htm

Ubuntu 14.04安裝Python 3.3.5  http://www.linuxidc.com/Linux/2014-05/101481.htm

CentOS上原始碼安裝Python3.4  http://www.linuxidc.com/Linux/2015-01/111870.htm

Ubuntu 14.04下Python資料處理環境搭建  http://www.linuxidc.com/Linux/2017-01/139568.htm

Python Paramiko模組安裝和使用  http://www.linuxidc.com/Linux/2017-01/139973.htm

《Python開發技術詳解》.( 周偉,宗傑).[高清PDF掃描版+隨書視訊+程式碼] http://www.linuxidc.com/Linux/2013-11/92693.htm

在CentOS 6.5上安裝Python2.7  http://www.linuxidc.com/Linux/2016-10/136206.htm

Ubuntu 14.04 LTS下編譯安裝Open Babel和Python語言系結 http://www.linuxidc.com/Linux/2017-01/139569.htm

本文永久更新連結地址http://www.linuxidc.com/Linux/2017-02/140406.htm


IT145.com E-mail:sddin#qq.com