shell脚本案例-Python安装脚本
2023-06-13 09:12:42 时间
案例需求
使用shell脚本安装Python环境
应用场景
服务器业务初始化
解决问题
避免人工多次安装,节省人工成本 避免人工错误,提高工作效率
脚本思路
1、获得软件包 2、源码安装 3、升级pip命令
案例代码
#!/bin/bash
#Description: python install from zutuanxue(http://www.zutuanxue.com)
#Release: python 3.7.6
#Auther: zutuanxue
#Email:
#OS: Centos 8.X
#variables
python_download_url=https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
python_source_pkg=Python-3.7.6.tgz
python_code=Python-3.7.6
#functions
#安装前准备,安装必要依赖包
per_install () {
if ( ! yum -y install gcc-* openssl-* libffi-devel sqlite-devel &>/dev/null );then
#if ( ! yum -y install gcc-* openssl-* libffi-devel sqlite-devel ) &>/dev/null ;then
echo -e "\033[31m network connection error,exit... \033[0m"
exit 130
fi
}
#安装python
install () {
#下载软件包
wget $python_download_url
#解压软件包
if [ -f $python_source_pkg ];then
tar xf $python_source_pkg
[ $? -ne 0 ]&&echo "$python_source_pkg unzip fail"&&exit 1
cd $python_code
#配置,开启ssl支持https
if ./configure --with-openssl=/usr/bin/openssl 1>/dev/null;then
#mv Modules/Setup Modules/Setup.bak
cp -f ../Setup Modules/
if make 1>/dev/null;then
#if make ;then
if make install 1>/dev/null;then
#if make install ;then
#if pip3 install --upgrade pip 1>/dev/null;then
#安装完成后更新pip
if pip3 install --upgrade pip;then
echo "python install success"
else
echo "pip3 install fail"
exit 1
fi
else
echo "python install fail"
exit 1
fi
else
echo "python make fail"
exit 1
fi
else
echo "python configure fail"
exit
fi
else
echo "not found $python_source_pkg"
exit 1
fi
}
per_install;install
rm -rf $python_code
rm -rf python_source_pkg
相关文章
- python实现K近邻算法案例
- python的安装教程_Python的安装
- python win32api messagebox_如何在Python中使用Win32 API?
- python fileinput_python模块fileinput
- python十进制转换_Python 进制转换
- python进制转换函数-Python中进制转换函数的使用
- python中矩阵的转置_[转]Python中的矩阵转置[通俗易懂]
- python基础系列教程——Python的安装与测试:python解释器、PyDev编辑器、pycharm编译器
- 在python中用来安装第三方库的常用工具_什么库用于安装管理Python扩展包
- python hexdump_笨办法学 Python · 续 练习 26:`hexdump`
- Python定时任务框架之Apscheduler 案例分享
- Python小案例(六)通过墒权法计算指标权重
- 【愚公系列】2023年03月 .NET CORE工具案例-C#调用Python的二种方式
- Python 进阶指南(编程轻松进阶):十五、面向对象编程和类
- Python基础语法-函数-迭代器
- Python 基于python实现的http+json协议接口自动化测试框架源码(实用改进版)详解编程语言
- Linux下安装Python的指南(linux下安装python)
- python-conda详解编程语言
- Linux环境下安装Python(linux装python)
- 使用 attrs 来告别 Python 中的样板
- 在Linux上安装Python学习快乐(linux下载python)
- Linux下从系统卸载Python(linux下卸载python)