Python Python3 自动安装脚本 (解决 Python 命令行方向箭头移动问题)

duliang · 2019年12月14日 · 387 次阅读
本帖已被设为精华帖!

由于工作需要,系统自带的 Python2.7 已经不能满足要求了,自己写了个安装脚本,自定义版本号然后执行即可。

#!/usr/bin/env bash

###############################################################################
# 安装Python 3
# Author : duliang <www.dba100.com>
# Desc   : CentOS 7 通过
###############################################################################

PY_VERSION=3.7.4 # 版本号

if [ -d /usr/local/python3 ]; then
    echo 'python3 already exists!'
    exit
fi

yum install -y gcc gcc-c++
yum install -y zlib-devel openssl-devel
yum install -y wget
yum install -y libffi-devel # 解决Python3.7: ModuleNotFoundError: No module named '_ctypes'
yum install -y readline-devel # 解决Python命令行方向箭头移动问题

cd /usr/local/src
if [ ! -f Python-$PY_VERSION.tgz ]; then
    wget -c https://www.python.org/ftp/python/$PY_VERSION/Python-$PY_VERSION.tgz
fi
tar zxvf Python-$PY_VERSION.tgz && cd Python-$PY_VERSION
./configure --prefix=/usr/local/python3
make &&  make install

ln -fs /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

mkdir ~/.pip

cat > ~/.pip/pip.conf << EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com
EOF

pip3 list
lework 将本帖设为了精华贴 03月18日 15:06
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册