ubuntu16安装Python3.7

  • Post author:
  • Post category:python


ubuntu16系统自带了python2.7和python3.5;不要卸载ubuntu自带的python版本;ubuntu下不同版本的python可以共存,可直接安装python3.7。

1.升级包索引和软件

sudo apt update
sudo apt upgrade -y

2.安装编译所需包

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

3.下载Python3.7官网下载Python-3.7.4.tgz文件

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

4.解压Python安装包

tar -xzvf Python-3.7.4.tgz

5.编译和安装

cd Python-3.7.4
./configure --prefix=/usr/local/src/python37  # 配置安装位置
sudo make
sudo make install

6.建立软连接

sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3.7
sudo ln -s /usr/local/src/python37/bin/pip3.7 /usr/bin/pip3.7

接下来你就可以使用python3.7,而不会影响系统自带的python2.7和python3.5如果你想用python3.7替换掉系统默认的python3

sudo rm -rf /usr/bin/python3
sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3

输入python3默认就是你安装好的python3.7了

卸载python(如果需要)

sudo apt remove python3.7



版权声明:本文为hello_world_banni原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。