Linux系统安装更新Python3.x版本详细步骤

11,539
BrightData

Linux系统中默认自带的Python版本都比较低,通常是Python2.7,对于一些要求Python高版本的项目来说就会无法继续运行,所以需要升级到python3环境,本文提供下升级Python版本的详细代码,方便后面用于查询。

Linux系统安装更新Python3.x版本详细步骤

Debian/Ubuntu系统

安装Python3.8文章源自技术白-https://jishubai.com/1319.html

cat <<"EOF" | bash
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev -y && \
curl -O https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz && \
tar -xf Python-3.8.2.tar.xz && \
cd Python-3.8.2 && \
./configure --enable-optimizations && \
make -j 4 && \
sudo make altinstall && \
python3.8 --version
EOF

apt update && apt install python3-pip

安装Python3.10文章源自技术白-https://jishubai.com/1319.html

apt update && apt upgrade -y

apt install git wget curl screen htop vim sudo -y

apt-get --purge remove python3 python3-pip -y

apt install build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev -y

wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz

tar -xzvf Python-3.10.8.tgz

cd Python-3.10.8

./configure --prefix=/usr/local/python3

make altinstall

rm -f /usr/bin/python3
rm -f /usr/local/bin/pip3
ln -s /usr/local/python3/bin/python3.10 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.10 /usr/bin/pip3

python3 -m pip install --upgrade pip

python3 -V && pip3 -V

Centos7系统

安装Python3.8文章源自技术白-https://jishubai.com/1319.html

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel wget

wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
tar -xf Python-3.8.2.tar.xz
cd Python-3.8.2
./configure prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3

python3.8 --version

这里没有直接链接到python,所以输入python的话还是会进入python2.7,输入python3才会进入python3.8,因为yum需要用到python2才能执行,执意要链接的话需要手动修改yum配置:文章源自技术白-https://jishubai.com/1319.html

vi /usr/bin/yum 
把 #! /usr/bin/python 修改为 #! /usr/bin/python2 

vi /usr/libexec/urlgrabber-ext-down 
把 #! /usr/bin/python 修改为 #! /usr/bin/python2

配置默认版本

如果机器内有多个python版本,可以通过设置优先级来默认使用哪个版本文章源自技术白-https://jishubai.com/1319.html

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
文章源自技术白-https://jishubai.com/1319.html文章源自技术白-https://jishubai.com/1319.html
  1. 本站TG群组skill_blog   联系博主:nbskill (微信协助) 苹果ID号:曙光商店
IPRoyal
 
技术白