目录

Ubuntu安装任意版本的Python

https://pic.imgdb.cn/item/60e468e75132923bf8cc429b.png

优先安装依赖环境

1
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 gcc

1、下载所需版本python

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

2、然后解压

1
tar -xvf Python-3.6.4.tgz

3、创建安装路径

1
mkdir /usr/local/python3

4、进入解压后的文件夹

1
2
3
./configure --prefix=/usr/local/python3
sudo make
sudo make install

5、修改软连接

1
2
3
4
mv /usr/bin/python3 /usr/bin/python3_bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python
PATH=$PATH:$HOME/bin:
PATH=$PATH:$HOME/bin:/usr/local/python3/bin

6、完成