宝塔面板在Ubuntu18.04+Python3下,基本可以秒装LNMP,不过ubuntu默认还是python2.7,现在我们切换成3

1.安装Python3及pip3

sudo apt-get install python3
sudo apt install python3-pip

2.将Python3设置为默认

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

3.验证

python --version
Python 3.6.5 #显示这个就说明切换成功

4.Python2、3切换

sudo update-alternatives --config python

会出现如下界面

There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3   150       auto mode
  1            /usr/bin/python2   100       manual mode
  2            /usr/bin/python3   150       manual mode

Press <enter> to keep the current choice[*], or type selection number: 

输入1,即可切换python2;输入0,即可切换python3,检查一下

python --version
Python 2.7.15rc1

参考原文:Ubuntu-18.04Python2与Python3自由切换

Last modification:February 21st, 2020 at 02:39 pm
If you think my article is useful to you, please feel free to appreciate