ubuntu18安装Python3.7

ubuntu18安装Python3.7

  1. ubuntu18系统自带了python2.7和python3.6;
  2. 不要卸载ubuntu自带的python版本;
  3. 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.6

如果你想用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

你可能感兴趣的:(Linux之美)