配置依赖环境
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev
下载解压源码
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
cd /root
tar xf Python-3.8.0.tgz
进入目录安装依赖
cd Python-3.8.0/
sudo apt-get install python-dev
sudo apt-get install libffi-dev
sudo apt-get install libssl-dev
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
编译及安装
./configure prefix=/usr/local/python3
make && make install
修改软连接(配置全局变量)
#将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
#添加python3的软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
#测试是否安装成功了
python -V
安装/升级pip
执行安装
#这句是给(python2.7安装pip)
sudo apt-get install python-pip
#这句是给python3安装pip
sudo apt-get install python3-pip
执行升级
pip install --upgrade pip
pip3 install --upgrade pip
升级pip时出现了以下问题:
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
使用命令即可
python -m pip install --upgrade pip
让pip连接到python3.8
vim ~/.bashrc
文件结尾添加
alias pip=/usr/bin/pip
保存后,使文件生效
source ~/.bashrc