离线安装python

0x00 背景

工作中会遇到服务器没有网络的情况,也需要使用python,这个时候提前打包并写好安装脚本就显得尤为重要。

0x01 实践

编写install.sh


  
  
  1. function compile_py36(){
  2. rm -fr /usr/local/python36
  3. mkdir /usr/local/python36
  4. tar -xvf Python-3.6.8.tar.xz -C /usr/local/python36/
  5. cd /usr/local/python36/Python-3.6.8
  6. ./configure --with-ssl --prefix=/usr/local/python36
  7. make && make install
  8. ln -s /usr/local/python36/bin/python3 /usr/bin/python3.6
  9. ln -s /usr/local/python36/bin/python3 /usr/bin/python3
  10. }
  11. RED= "echo -en \\E[4;31m"
  12. GREEN= "echo -en \\E[7;32m"
  13. RESET= "echo -en \\E[0;39m"
  14. dir=` pwd`
  15. s=`python3.6 -V`; if [[ $s == '' ]]
  16. then
  17. compile_py36
  18. else
  19. s1=`python3.6 -m pip -V`;
  20. if [[ $s1 == '' ]]
  21. then
  22. $RED && echo "检测到系统自带python3不可用,即将卸载系统自带python3" && $RESET
  23. yum remove python36 -y
  24. compile_py36
  25. else $RED && echo "检测到系统有python3.6环境,先尝试使用系统自带的python3.6,如果不可用请先执行yum remove python36 -y卸载再重新执行本脚本" && $RESET
  26. fi
  27. fi
  28. cd $dir ## 安装包上传的目录
  29. rpm -ivh libtirpc-0.2.4-0.16.el7.x86_64.rpm
  30. rpm -ivh python3-3.6.8-18.el7.x86_64.rpm python3-libs-3.6.8-18.el7.x86_64.rpm python3-setuptools-39.2.0-10.el7.noarch.rpm python3-pip-9.0.3-8.el7.noarch.rpm
  31. rpm -ivh python3-devel-3.6.8-18.el7.x86_64.rpm
  32. s2=`python3.6 -m pip`; if [[ $s2 == '' ]]
  33. then
  34. python3.6 -m ensurepip
  35. else echo "已安装pip"
  36. fi

我喜欢把安装脚本和离线包打包到一个压缩包,并用另一个脚本insallpy36.sh启动


  
  
  1. unzip -o install_py.zip
  2. cd install_py
  3. chmod 550 install.sh
  4. ./install.sh

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值