Repository navigation
Expand file tree
/
Copy pathchange_python_version.txt
More file actions
executable file
·54 lines (35 loc) · 2.05 KB
/
Copy pathchange_python_version.txt
File metadata and controls
executable file
·54 lines (35 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
WORKED ON MAC, AND LINUX
Check the location of python 3
$ which python3
/usr/local/bin/python3
Write alias in bash_profile
vi ~/.bash_profile
alias python='/usr/local/bin/python3'
Reload bash_profile
source ~/.bash_profile
Confirm python command
$ python --version
Python 3.6.5
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if it is your first time follow these instruction
1. Creating alias in bashrc:
We can create an alias within user’s home directory and add it to the bashrc. But it will only work for the current user.
Open the bashrc file by using the following command:
>> nano ~/.bashrc
2. Add the following line to the below of the bashrc file .
>> alias python=‘/usr/bin/python3.7’
3. Now if we use check python version using ‘python -V’, it will return 3.7.2. And if we run the program.py file using ‘python program.py’, then it will be run by python3.5 executable.
Using update-alternatives:
To switch between python version over the all users, we can use update-alternatives command.
We will set priority of each version using update-alternatives. Python executable with the highest priority will be used as default python version.
We will set the priority by the following commands:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 4
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 5
Here I set the priority of python 2.7, 3.5, 3.6, 3.7, 3.8 as 1, 2, 3, 4, 5. As the python3.8 has the highest priority, the default python executable is python3.8 now.
4. To switch between any versions, we can use the following command:
>> sudo update-alternatives --config python
you can simply follow number 1, 2, 4
and if you've done this before, you can simply follow number 4