如何将 Python 恢复到原始版本

如何将 Python 恢复到原始版本

几个月前,我在 Ubuntu 中将 Python 默认版本设为 Python 3,但我不知道该怎么做。现在我尝试安装 pygame,但出现了很多错误。我觉得这是因为我的默认 Python 被更改了。我想恢复到更改之前的原始状态。

我对 Linux 和 Python 都很陌生,因此如果您需要任何其他信息,请告诉我。

更新 ls -l /usr/bin | grep python

-rwxr-xr-x 1 root   root        1824 Feb  10 16:51 activate-global-python-argcomplete3
lrwxrwxrwx 1 root   root          26 Mei  18 17:10 dh_pypy -> ../share/dh-python/dh_pypy
-rwxr-xr-x 1 root   root        1056 Dis  10  2015 dh_python2
lrwxrwxrwx 1 root   root          29 Mei  18 17:10 dh_python3 -> ../share/dh-python/dh_python3
lrwxrwxrwx 1 root   root          23 Jul   3 03:05 pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx 1 root   root          23 Jul   7 17:17 pdb3.5 -> ../lib/python3.5/pdb.py
lrwxrwxrwx 1 root   root          31 Jun  28 11:01 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root   root          26 Mei  18 17:10 pybuild -> ../share/dh-python/pybuild
lrwxrwxrwx 1 root   root          16 Jul  18 20:49 python -> /usr/bin/python3
lrwxrwxrwx 1 root   root           9 Jun  28 11:01 python2 -> python2.7
-rwxr-xr-x 1 root   root     3546104 Jul   3 03:05 python2.7
lrwxrwxrwx 1 root   root          33 Jul   3 03:05 python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root   root          16 Dis  10  2015 python2-config -> python2.7-config
-rwxr-xr-x 1 root   root         319 Feb  24 22:53 python2-jsonschema
-rwxr-xr-x 1 root   root         151 Nov  23  2015 python2-pbr
lrwxrwxrwx 1 root   root           9 Jun  28 11:01 python3 -> python3.5
-rwxr-xr-x 2 root   root     4456272 Jul   7 17:17 python3.5
lrwxrwxrwx 1 root   root          33 Jul   7 17:17 python3.5-config -> x86_64-linux-gnu-python3.5-config
-rwxr-xr-x 2 root   root     4456272 Jul   7 17:17 python3.5m
lrwxrwxrwx 1 root   root          34 Jul   7 17:17 python3.5m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root   root          16 Mac  23 19:00 python3-config -> python3.5-config
lrwxrwxrwx 1 root   root          10 Jun  28 11:01 python3m -> python3.5m
lrwxrwxrwx 1 root   root          17 Mac  23 19:00 python3m-config -> python3.5m-config
-rwxr-xr-x 1 root   root        2553 Feb  10 16:51 python-argcomplete-check-easy-install-script3
lrwxrwxrwx 1 root   root          16 Dis  10  2015 python-config -> python2.7-config
lrwxrwxrwx 1 root   root          29 Jun  28 11:01 pyversions -> ../share/python/pyversions.py
-rwxr-xr-x 1 root   root        1289 Feb  10 16:51 register-python-argcomplete3
-rwxr-xr-x 1 root   root        2909 Jul   3 03:02 x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root   root          34 Jul   7 17:17 x86_64-linux-gnu-python3.5-config -> x86_64-linux-gnu-python3.5m-config
-rwxr-xr-x 1 root   root        3185 Jul   7 17:14 x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root   root          33 Mac  23 19:00 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.5-config
lrwxrwxrwx 1 root   root          34 Mac  23 19:00 x86_64-linux-gnu-python3m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root   root          33 Dis  10  2015 x86_64-linux-gnu-python-config -> x86_64-linux-gnu-python2.7-config

答案1

系统的默认版本是符号链接指向的版本/usr/bin/python。在 16.04 中应该是这样python2.7的,但是你改变了它(正如你所发现的,这是一个坏主意,因为 Ubuntu 中的许多程序都使用 Python,如果找到错误的版本,它们将无法工作),它指向的/usr/bin/python3是指向/usr/bin/python3.5

删除您更改的符号链接(不能只通过一个步骤就覆盖它):

sudo rm /usr/bin/python

并创建一个同名的新符号链接,指向正确的 Python 版本(它最初指向的版本)。对于你的情况是这样python2.7的:

sudo ln -s /usr/bin/python2.7 /usr/bin/python

现在python --version将为您提供Python 2.7.12(或 2.7。[某个数字],具体取决于安装的次要版本)

相关内容