脚本一键编译安装Python

脚本优化可联系ajunyu163@163.com交流

1. 文件集成

集成有这些文件:

[root@ansible install_python]# pwd
/ajunyu/scripts/install_python
[root@ansible install_python]# ll
total 25428
-rwxr-xr-x 1 root root       98 Oct 18 21:52 Centos.sh
-rwxr-xr-x 1 root root     3462 Oct 19 19:37 install.sh
-rw-r--r-- 1 root root      104 Oct 19 18:50 pip.conf
-rw-r--r-- 1 root root 26015299 Oct 18 21:50 Python-3.10.8.tgz
-rw-r--r-- 1 root root       13 Oct 18 21:56 requirements.txt
-rwxr-xr-x 1 root root      221 Oct 18 21:55 Ubuntu.sh

编译安装时需要将整个install_python目录复制到安装目录同级的目录下(不需要额外创建安装目录,install.sh会创建).

涉及修改的只有两个地方:Python的源码包requirements.txt.

Centos.sh 、Ubuntu.sh:用于安装对应系统的基础依赖;

pip.conf :pip源配置;

Python-3.10.8.tgz:Python源码包,可以更换需求版本的包;目录下只能有一个源码包,多个源码包install.sh无法区分Python目标版本;

requirements.txt:pip的依赖文件,用于安装pip模块,按需修改,可以为空;

install.sh: 安装脚本,需要用root用户来运行,只支持Centos和Ubuntu系统。

安装前请确保yum源或者sources.list能正常访问到包。

2. 脚本

install.sh

#!/bin/bash
#This script is userd to install python, must be executed as root.
#By Ajunyu,2022-10-19
set -e
#Define parameter
BaseDir=$(cd $(dirname $0);pwd)
InstallDir=$(echo $(cd  ${BaseDir};cd  ..;pwd))
Package=$(cd ${BaseDir};ls -l Python* | awk '{print $NF}')
Number=$(echo ${Package} | awk -F '-' '{print $2}' | awk -F '.t' '{print $1}')
Compile_path=Python-${Number}
pytho
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值