我在 WSL 中全新安装了 Ubuntu 18.04。到目前为止,我已经通过安装 Python 3.7.4 来设置系统,如下所示:
$ mkdir -p $HOME/bin $HOME/.local/bin
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update && sudo apt upgrade -y
$ sudo apt install python3-pip python3.7 python3.7-dev python3.7-doc python3.7-venv python3.7-distutils python3.7-tk
$ sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ sudo -H python3.6 get-pip.py
$ sudo -H python3.7 get-pip.py
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 10
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 20
$ sudo update-alternatives --set python3 /usr/bin/python3.7
现在,当 Python 3.6 被设置为系统默认设置时,一切都正常运行。但是,当我切换到 Python 3.7 作为默认设置时,事情就出错了。我看到的最奇怪的行为是,每当我在 bash 提示符下输入错误命令时,我都会收到来自 Python 的错误输出,如下所示:
joe@Tyrion:~$ VIM
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 28, in <module>
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
再次,将 Python 3.6 配置为默认配置,我得到了期望的输出。
joe@Tyrion:~$ sudo update-alternatives --set python3 /usr/bin/python3.6
[sudo] password for joe:
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in manual mode
joe@Tyrion:~$ VIM
VIM: command not found
有人能给我指点迷津吗?我在 Google 上搜索无果。我非常希望以 3.7 作为默认版本运行。