Coexistence of Python2 and Python3 under Ubuntu
- 2021-01-19 22:18:54
- OfStack
Linux system 1 usually comes with Python, and sometimes it downloads Python itself, so it is possible for Python2 and Python3 to exist simultaneously. So when we type python in Terminal, which Python is called up? This article is to solve this problem.
Version to view
Type at the terminal
python --version1
See python version information
I found that my version of python is 2.7.15rc1. However, I have installed python3, so how do I use python3? python3 can be opened directly with python3, and python2 can also be opened with python2.
But python is now the default python2, because it has a higher priority. How to change python to python3?
Modify python
Method 1: Modify the alias
python can be set to python3 by changing the alias alias
alias python='/usr/bin/python3'1
And put it in.bashrc
Approach 2: Modify the configuration
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
# add Python2 Optional, priority is 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
# add Python3 Optional, priority is 1
sudo update-alternatives --config python12345
Select python2. To set it to python3, just select 2 and enter ~
supplement
Load python2 and python3 with pip, be careful not to use each other's pip
sudo apt-get install python2-pip
sudo apt-get install python3-pip
---------------------
conclusion