Python

如何使python3.7預設

  • June 5, 2020

我已經安裝了 python3.7 但是我不知道如何使它成為預設的 python。

見下文:

~/Documents/robosuite$ python3.7
Python 3.7.1 (default, Oct 22 2018, 11:21:55) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
KeyboardInterrupt
>>> 

~/Documents/robosuite$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

我希望在使用命令時顯示 python3.7python3

簡單的解決方案是編輯.bashrc並放入這一行:

alias python3=python3.7

每當您編寫python3它時,它都會將其替換為python3.7.

或者您可以使用update-alternatives首選的命令,即:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

所以這裡python3.7會有更高的優先級python3.6。然後使用:

sudo update-alternatives --config python3

滿意按輸入鍵

引用自:https://unix.stackexchange.com/questions/496461