Ubuntu 16.04 amd64 (64bit)(纯净版)
自带python2.7和python3.5
执行"whereis python"查看当前安装的python
[root@root ~]# whereis python
python:/usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
0.配置依赖环境,如果不进行这步可能会出现一些问题
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz
2.解压下载的包
第一种方法
tar -xvJf Python-3.8.1.tar.xz
第二种方法
#解压
xz-d Python-3.8.1.tar.xz
tar-xf Python-3.8.1.tar
3.进入解压后的目录
cd Python-3.8.1/
4.安装依赖(非必要,可跳过此步骤,如在5步出错在执行本步骤)
执行下列命令安装依赖过程中,如有提示,一律 y 。
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
5.执行安装
./configure prefix=/usr/local/python3
make && make install
6.修改软连接(配置全局变量)
#将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
#添加python3的软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
#测试是否安装成功了
python -V
7.安装/升级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
from pip import main
修改一下pip配置
sudo vim /usr/bin/pip
改成
#原PIP配置文件frompip import mainif __name__ == '__main__':
sys.exit(main())
#修改为from pip import __main__ //修改
if __name__ == '__main__':
sys.exit(__main__._main())//修改
再次执行ok!
参考博文:https://blog.csdn.net/t8116189520/article/details/81976755