用编译安装比较费劲, 报错,
还是用 apt
一、安装
1- 更新
sudo apt update
sudo apt upgrade
2- 安装python
apt install python3
3- 验证:
这是3.12 版本
指定版本安装:
cd
sudo ./configure
二、 安装固定版本python3.9.8
1- 下载指定版本的源文件
https://www.python.org/ftp/python/
get https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tar.xz
2- 解压:
tar xf Python-3.9.8.tar.xz
3- 安装编译环境
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev
3- 初始化
自定义安装路径
cd /Python-3.9.8
./configure --prefix=/usr/local/python3.9.8
4-安装
sudo make && make install
设置环境变量
vim /etc/profile
PATH=$PATH:/usr/local/python3.9.8/bin
软连接
查看 软连接:
ls -l /usr/bin | grep python
然后
1# 将原python与python3命令改为python.bak与python.bak
sudo mv /usr/bin/python3 /usr/bin/python3.bak
2# 将我们刚装的python3.9.8指定运行命令为python与python3
sudo ln -s /usr/local/python3.9.8/bin/python3.9 /usr/bin/python
sudo ln -s /usr/local/python3.9.8/bin/python3.9 /usr/bin/python3
# 将原pip和pip3命令改为pip.bak与pip3.bak
sudo mv /usr/bin/pip /usr/bin/pip.bak
sudo mv /usr/bin/pip3 /usr/bin/pip3.bak
# 将我们刚装的python3.8.5的pip指定运行命令为pip与pip3
sudo ln -s /usr/local/python3.9.8/bin/pip3 /usr/bin/pip
sudo ln -s /usr/local/python3.9.8/bin/pip3 /usr/bin/pip3
然后验证一下: