天天看點

linux centos7 編譯安裝python3 --shell腳本

#!/bin/bash
yum install -y wget
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
yum -y groupinstall "Development tools"
cd /usr/local/src/
# https://www.python.org/ftp/python       # 官網下載下傳
wget http://work.eisc.cn/ruanjian/Python-3.7.0.tar.xz
yum install -y star
tar xvf Python-3.7.0.tar.xz
mv Python-3.7.0 /usr/local/python-3.7
cd /usr/local/python-3.7/
 ./configure --prefix=/usr/local/sbin/python-3.7                # 将python3.7安裝到/usr/local/sbin/python-3.7目錄下
make && make install                                                    # 安裝完成後,若出現以下兩行,說明安裝成功;
# 出現以下兩行是安裝成功
# Installing collected packages: setuptools, pip
# Successfully installed pip-10.0.1 setuptools-39.0.1
rm -rf /usr/bin/python3
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python3
ls /usr/bin/ |grep python
# 将python指令通過軟連結指向到python3指令(就是上面那一大串/usr/local/sbin/python-3.7/bin/python3)
NR=`cat -n /usr/bin/yum | grep "\!/usr/bin/python" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/\!\/usr\/bin\/python.*/\!\/usr\/bin\/python2.7/g" /usr/bin/yum
sed -i "s/\/usr\/bin\/python.*/\/usr\/bin\/python2.7/g" /usr/libexec/urlgrabber-ext-down
ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip  # pip 重定向到python3
python3 -V          # 檢視python3的詳細版本
pip --version                                                                   # 檢視pip版本
################### 安裝pip 源 ######################
yum -y install zlib-devel readline-devel libffi-devel python-devel openssl-devel gcc git
pip install --upgrade pip  -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
                                                                                        # 安裝 pip 源
cd ~
mkdir .pip
cd .pip
echo "
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
" > pip.conf                                                                    # 配置 pip 源
yum install -y paramiko                                                 # 遠端控制工具
###################################################
## 一鍵安裝:    
yum -y install screen           # 安裝工具包
screen -S eisc                          # 建立視窗名字為eisc
echo "screen 建立視窗背景運作,如果斷網,請使用指令screen -ls  檢視ID ;再次指令進入 screen -x ID"
yum install -y wget ; wget eisc.cn/file/shell/yumpython3.sh ; chmod 755 yumpython3.sh ;  sh yumpython3.sh