更新软件包索引:
sudo apt-get update
安装必要的编译器和开发工具:
sudo apt-get install build-essential checkinstall
安装依赖库:
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
下载Python 3.7.X源码:
wget https://www.python.org/ftp/python/3.7.X/Python-3.7.X.tgz
X为Python 3.7的版本号,比如3.7.4
解压源码:
tar -xvf Python-3.7.X.tgz
进入解压后的目录:
cd Python-3.7.X
编译安装:
./configure --enable-optimizations
make altinstall
检查安装的Python版本:
python3.7 -V
安装pip3:
sudo apt-get install python3-pip
检查pip3版本:
pip3 -V
查看当前默认的Python版本:
python -V
查看已安装的Python版本:
ls /usr/bin/python*
查看当前默认的pip版本:
pip -V
查看已安装的pip版本:
ls /usr/bin/pip*
创建软链接:
sudo ln -s /usr/bin/python3.7 /usr/bin/python
sudo ln -s /usr/bin/pip3 /usr/bin/pip
检查是否切换成功:
python -V
pip -V
本文链接:http://task.lmcjl.com/news/6905.html