阿里云的DSW实例自带的镜像很少而且并不好用,所以我在这里写三个一键编译安装Python3.8,Python3.9,Python3.10的Shell脚本。
安装Python3.8
wget https://www.smallbamboo.cn/install_python38.sh && chmod +x install_python38.sh && ./install_python38.sh
#!/bin/bash
# 提示用户确认是否继续
read -p "此脚本将更新系统并安装Python 3.8.10以及相关依赖。是否继续?(y/n) " -n 1 -r
echo # (可选) 换行
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "操作已取消。"
exit 1
fi
# 更新系统
echo "正在更新系统..."
sudo apt update && sudo apt upgrade -y
# 安装必要依赖
echo "正在安装必要的开发工具及依赖..."
sudo apt install -y build-essential libssl-dev zlib1g-dev libncurses5-dev \
libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev \
libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
# 下载并安装Python 3.8.10
echo "下载并安装Python 3.8.10..."
cd /usr/src
sudo wget https://www.smallbamboo.cn/Python-3.8.10.tgz
sudo tar xzf Python-3.8.10.tgz
cd Python-3.8.10
# 配置并编译Python
echo "配置并编译Python 3.8.10..."
sudo ./configure --enable-optimizations
sudo make altinstall
# 设置Python 3.8为默认版本
echo "配置Python和pip版本..."
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.8 1
sudo update-alternatives --config python
sudo update-alternatives --config python3
# 设置pip3.8为默认pip版本
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.8 1
sudo update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.8 1
sudo update-alternatives --config pip
sudo update-alternatives --config pip3
# 检查版本
echo "检查安装结果..."
python --version
python3 --version
pip --version
pip3 --version
echo "Python 3.8.10 安装完成!"
安装Python3.9
wget https://www.smallbamboo.cn/install_python39.sh && chmod +x install_python39.sh && ./install_python39.sh
#!/bin/bash
# 提示用户确认是否继续
read -p "此脚本将更新系统并安装Python 3.9.17以及相关依赖。是否继续?(y/n) " -n 1 -r
echo # (可选) 换行
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "操作已取消。"
exit 1
fi
# 更新系统
echo "正在更新系统..."
sudo apt update && sudo apt upgrade -y
# 安装必要依赖
echo "正在安装必要的开发工具及依赖..."
sudo apt install -y build-essential libssl-dev zlib1g-dev libncurses5-dev \
libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev \
libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
# 下载并安装Python 3.9.17
echo "下载并安装Python 3.9.17..."
cd /usr/src
sudo wget https://www.smallbamboo.cn/Python-3.9.17.tgz
sudo tar xzf Python-3.9.17.tgz
cd Python-3.9.17
# 配置并编译Python
echo "配置并编译Python 3.9.17..."
sudo ./configure --enable-optimizations
sudo make altinstall
# 设置Python 3.9为默认版本
echo "配置Python和pip版本..."
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.9 1
sudo update-alternatives --config python
sudo update-alternatives --config python3
# 设置pip3.9为默认pip版本
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1
sudo update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.9 1
sudo update-alternatives --config pip
sudo update-alternatives --config pip3
# 检查版本
echo "检查安装结果..."
python --version
python3 --version
pip --version
pip3 --version
echo "Python 3.9.17 安装完成!"
安装Python3.10
wget https://www.smallbamboo.cn/install_python310.sh && chmod +x install_python310.sh && ./install_python310.sh
#!/bin/bash
# 提示用户确认是否继续
read -p "此脚本将更新系统并安装Python 3.10以及相关依赖。是否继续?(y/n) " -n 1 -r
echo # (可选) 换行
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "操作已取消。"
exit 1
fi
# 更新系统
echo "正在更新系统..."
sudo apt update && sudo apt upgrade -y
# 安装必要依赖
echo "正在安装必要的开发工具及依赖..."
sudo apt install -y build-essential libssl-dev zlib1g-dev libncurses5-dev \
libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev \
libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
# 下载并安装Python 3.10
echo "下载并安装Python 3.10..."
cd /usr/src
sudo wget https://www.smallbamboo.cn/Python-3.10.12.tgz
sudo tar xzf Python-3.10.12.tgz
cd Python-3.10.12
# 配置并编译Python
echo "配置并编译Python 3.10..."
sudo ./configure --enable-optimizations
sudo make altinstall
# 设置Python 3.10为默认版本
echo "配置Python和pip版本..."
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1
sudo update-alternatives --config python
sudo update-alternatives --config python3
# 设置pip3.10为默认pip版本
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.10 1
sudo update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.10 1
sudo update-alternatives --config pip
sudo update-alternatives --config pip3
# 检查版本
echo "检查安装结果..."
python --version
python3 --version
pip --version
pip3 --version
echo "Python 3.10 安装完成!"
© 版权声明
文章版权归作者所有,请勿转载至任何平台。
THE END
暂无评论内容