由于经常需要配置不同版本的python环境等问题,所以写了这篇总结,参考文献后续也会列出来。
本文主要是ubuntu18.04在已安装pyhon3.6的环境中安装python3.5。实现python3自由切换。
1.安装python3.5
sudo add-apt-repository ppa:deadsnakes/ppa
apt-get update
sudo apt-get install python3.5-dev
2.创建python3选项与切换
依次通过下面命令实现:
sudo update-alternatives --install 软链接 替代名称 python对应路径 优先级
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 100
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 150
sudo update-alternatives --config python3
运行后输出显示如下:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 100
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python3 (python3) in auto mode
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 150
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 150
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode
sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.6 150 auto mode
1 /usr/bin/python3.5 100 manual mode
2 /usr/bin/python3.6 150 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python3 (python3) in manual mode
python3
Python 3.5.9 (default, Nov 24 2019, 01:35:13)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
3.python3.5创建软链接
该部分与其他部分是独立的,只是在这里的时候,我想到将这个也记录以下(为python3.5创建python3的软链接):
sudo ln -s /usr/bin/python3.5 /usr/bin/python3