Python3.5升级到3.9.2
0、准备工作
删除Python3的软链接,它是指向Python3.5的
sudo rm /usr/bin/python3
其他问题,网上有说要先安装libffi-dev
sudo apt install libffi-dev
删除lsb_release,可能会出现以下错误
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1
sudo cp /usr/bin/lsb_release /home/lsb_release #先备份一下
sudo rm -rf /usr/bin/lsb_release
1、下载Python源码
https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tar.xz
命令方式为:
cd /home
curl https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tar.xz -o Python-3.9.2.tar.xz
2、解压
cd /home
xz -d Python-3.9.2.tar.xz
tar -xvf Python-3.9.2.tar
3、编译
cd Python-3.9.2
sudo ./configure --prefix=/usr/local/python3.9
sudo make
sudo make install
4、配置
将原来的python3指向Python3.9.2
sudo ln -s /usr/local/python3.9/bin/python3.9 /usr/bin/python3
环境变量配置
echo 'export PATH=/usr/local/python3.8/bin:$PATH' >>~/.bashrc
source ~/.bashrc
5、验证
python3 -V
Python 3.9.2
6、使用国内镜像源
mkdir ~/.pip
cd ~/.pip
sudo vi ~/.pip/pip.conf
将以下内容贴入pip.conf中去
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn # trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任
7、安装升级第三方库
sudo apt install python3-pip
python3 -m pip install --upgrade pip
WARNING: The scripts pip, pip3 and pip3.9 are installed in '/usr/local/python3.9/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
echo 'export PATH=/usr/local/python3.9/bin:$PATH' >>~/.bashrc
source ~/.bashrc
python3 -m pip install pandas
python3 -m pip install numpy
python3 -m pip install tensorflow