Python

Python 3.7 似乎不想安裝(仍然顯示 2.7.17?)

  • March 28, 2020

我正在嘗試在我的 Ubuntu 18.04 伺服器上安裝**Python 3.7 。**遵循這些指示:

https://phoenixnap.com/kb/how-to-install-python-3-ubuntu

sudo apt update
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7

但在那之後,如果我這樣做:

root@west:~# python --version
Python 2.7.17

我究竟做錯了什麼?如果我嘗試再次安裝它,它會告訴我它已經安裝了?

root@west:~# sudo apt install python3.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3.7 is already the newest version (3.7.7-1+bionic1).
0 upgraded, 0 newly installed, 0 to remove and 32 not upgraded.

兩者都已安裝,但有一個指向 python2.7 的連結。

如果你這樣做ls -l /usr/bin/python,它將指向 python2.7,如下所示:

root@5d9377c79b0c:/# which python
/usr/bin/python
root@5d9377c79b0c:/# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Apr 16  2018 /usr/bin/python -> python2.7
root@5d9377c79b0c:/# which python3.7
/usr/bin/python3.7

刪除連結並創建一個新連結python3.7

rm /usr/bin/python
ln -s /usr/bin/python3.7 /usr/bin/python

root@5d9377c79b0c:/# python –version

Python 3.7.5

引用自:https://serverfault.com/questions/1008708