Python 2.7.6環境搭建

來源:互聯網
上載者:User

Python 2.7.6環境搭建

為何寫指令碼

每次用新的機器,都要把python的環境給安裝一遍~so,這是一件很操蛋的問題,就shell練手寫了一個code,嘿嘿,渣渣技術~

測試環境

我愛vagrant,一條命令直接還原成乾淨的測試環境,大愛啊~

指令碼如下:


#!/bin/bash

# Auther: zhuima

# Date:  2014-06-26

# Function: create python env

#

 

 

REVTAL=0

 

# import Functions

 

. /etc/rc.d/init.d/functions

 

# check network

 

. /etc/sysconfig/network

 

if [ $NETWORKING = 'no' ];then

    exit $REVTAL

fi

 

# install epel yum source

 

function epel_install(){

    if rpm --version &>/dev/null;then

        rpm -ivh  http://mirrors.ustc.edu.cn/Fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

    else

        exit $REVTAL

        print "please checking your yum configure!"

    fi

}

 

 

# install base packages

 

function base_packages(){

    if yum repolist &>/dev/null;then

        yum install yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel patch -y

    else

        exit $REVTAL

        print "please checking your yum configure!"

    fi

}

 

 

# install pip

 

function pip_install(){

    if yum repolist &>/dev/null;then

        yum install python-pip -y

    else

        exit $REVTAL

            print "please checking your yum configure!"

        fi

}

 

# install ipython

 

function ipython_install(){

    if yum repolist &>/dev/null;then

        yum install ipython -y

    else

    exit $REVTAL

        print "please checking your yum configure!"

    fi

}

 

# install pyenv   

 

function pyenv_install(){

    if git --version  &>/dev/null;then

        cd /`whoami` && git clone git://github.com/yyuu/pyenv.git .pyenv 

    else

        yum install git -y

        cd /`whoami` && git clone git://github.com/yyuu/pyenv.git .pyenv 

    fi

}

 

# setting pyenv env

 

function pyenv_env(){

 

echo 'export PYENV_ROOT=$HOME/.pyenv' >> /etc/profile

echo 'export PATH=$PYENV_ROOT/bin:$PATH' >> /etc/profile

#echo 'eval $(pyenv init -)' >> /etc/profile

 

# exec pyenv.sh

if [ -e /etc/profile ];then

    source  /etc/profile

else

    echo "Files is not exists"

    exit $REVTAL

fi

 

}

 

# install python 2.7.6

 

function python_install(){

    if pyenv versions &>/dev/null;then

        pyenv install 2.7.6

    else

        exit $REVTAL

        print "please checking your pyenv configure"

    fi

}

 

# install ansible

 

function install_ansible(){

    if pip --version &>/dev/null;then

        pip install ansible

    else

        yum install pip -y

        pip install ansible

    fi

 

}

 

while :;do

cat << EOF

+-------------------------------------------+

|1、Install epel_install                    |

|2、Install base_packages                  |

|3、Install pip_install                    |

|4、Install ipython_install                |

|5、Install pyenv_install                  |

|6、Install pyenv_env                      |

|7、Install python2.7.6_install            |

|8、One-Click Setup                        | 

|9、[Q|q|quit] to quit                      |

+-------------------------------------------+

EOF

 

read -p "select which one packages you want to install: " choice

 

case $choice in

    1)

      epel_install

      ;;

    2)

      base_packages

      ;;

    3)

      pip_install

      ;;

    4)

      ipython_install

      ;;

    5) 

      pyenv_install

      ;;

    6)

      pyenv_env

      ;;

    7)

      python2.7.6_install

      ;;

    8)

      epel_install

      base_packages

      pip_install

      ipython_install

      pyenv_install

      pyenv_env

      python_install

          source /etc/profile

      ;;

    Q|q|quit)

      exit $REVTAL

      ;;

    *)

      echo "Usage: select one number(1|2|3|4|5|6|7|8|9)"

      exit $REVTAL

      ;;

esac

done

更多詳情見請繼續閱讀下一頁的精彩內容:

 

《Python核心編程 第二版》.(Wesley J. Chun ).[高清PDF中文版]

《Python開發技術詳解》.( 周偉,宗傑).[高清PDF掃描版+隨書視頻+代碼]

Python指令碼擷取Linux系統資訊

在Ubuntu下用Python搭建案頭演算法交易研究環境

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.