ubuntu16.04下python2python3环境选择与python升级
Posted Richal Wang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu16.04下python2python3环境选择与python升级相关的知识,希望对你有一定的参考价值。
参考链接:https://www.jianshu.com/p/63c1f22e1fed
Ubuntu中python版本问题:
- 添加PPA:
sudo add-apt-repository ppa:jonathonf/python-3.6
- 查看更新和安装更新:
sudo apt-get update
sudo apt-get install python3.6
- 更换命令行中的python默认版本
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
-
查看python默认版本
python -V
-
切换版本:
sudo update-alternatives --config python3
Ubuntu中python升级到3.6:
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
sudo apt install spyder3
sudo rm /usr/bin/python
sudo ln -s /usr/local/bin/python3.6 /usr/bin/python
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
sudo update-alternatives --config python3
python -V
更新:
2018-05-29 08:58:06
升级到python3.6 后使用pip install遇到问题:
import apt File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module> import apt_pkg ModuleNotFoundError: No module named ‘apt_pkg‘ Original exception was: Traceback (most recent call last): File "/home/osk/.local/bin/pip3", line 7, in <module> from pip._internal import main ModuleNotFoundError: No module named ‘pip._internal‘
解决方案:
重新将ubuntu16.04默认的python3.5版本设置为优先级
以上是关于ubuntu16.04下python2python3环境选择与python升级的主要内容,如果未能解决你的问题,请参考以下文章