手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Python 2.7.6环境搭建

[日期:2014-06-27] 来源:Linux社区  作者:lovelace [字体: ]

为何写脚本

每次用新的机器,都要把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

更多详情见请继续阅读下一页的精彩内容http://www.linuxidc.com/Linux/2014-06/103774p2.htm

 

《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm

《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htm

Python脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm

Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htm

linux
相关资讯       Python环境搭建  Python 2.7.6 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款