该脚本主要是在Centos系统上使用源码安装Python3.7,安装后可以调用python3和pip3来进行使用,同时不与系统Python2.7冲突,还额外加入了腾讯的pip源来加速pip3下载包。
脚本使用方法如下:
- 创建文件
install_py37.sh
,写入以下 shell 脚本
- 赋予执行权限,
chmox +x install_py37.sh
- 执行脚本,
./install_py37.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #!/bin/env bash
wget https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz
yum -y install wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel xz-devel
tar zvxf Python-3.7.12.tgz -C /usr/local/src cd /usr/local/src/Python-3.7.12
./configure prefix=/usr/local/python3 --enable-shared
make -j8
make install
make clean
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
ln -s /usr/local/python3/lib/libpython3.7m.so.1.0 /usr/lib/libpython3.7m.so.1.0
ldconfig
echo -e "\033[1;42;37m[$(date "+%Y/%m/%d %H:%M:%S")] [Check]: 检查Python版本\033[0m" python3 --version echo -e "\033[1;42;37m[$(date "+%Y/%m/%d %H:%M:%S")] [Check]: 检查Python版本\033[0m"
mkdir ~/.pip3/ echo "extra-index-url = https://mirrors.cloud.tencent.com/pypi/simple" >> ~/.pip3/pip.conf
|
主要是参考了这篇文章:CentOS 7 安装 Python 3.7
不同点在于将原本的链接路径和安装结果改为了python3和pip3。