0

I have a fresh install of Ubuntu 18.04 in WSL. Thus far, I have set up the system by installing Python 3.7.4 as follows:

$ 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

Now, when Python 3.6 is set as the system default, everything functions normally. However, when I switch to Python 3.7 being the default things go awry. The oddest behavior I see is whenever I type a bad command at the bash prompt I get error output from Python as shown here:

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'

Again, with Python 3.6 configured as default, I get the output I would expect.

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

Can anyone point me in the right direction here? My Google searches have been fruitless. I'd very much like to run with 3.7 as the default.

3
  • This is a common new-power-user mistake. DO NOT CHANGE the system-provided version of Python - doing so will break your system. Many important services depend upon Python, and a few break when versions change. You can run with different versions all you like (tools like venv and conda are good for that). Tips for success: DON'T remove or replace the system-provided Python, and DON'T change the /usr/bin/python3 symlink to point to a different version of Python. Within those two minor constraints, the world is your oyster.
    – user535733
    Sep 12 '19 at 1:36
  • @mchid I tried that but it didn't install pip for Python 3.7.
    – Joe Paris
    Sep 12 '19 at 2:04
  • @user535733 Thanks, I know that tyring to change the system Python from 2.x to 3.x is a very bad idea but I was hoping that going from 3.6 to 3.7 would be fairly innocuous.
    – Joe Paris
    Sep 12 '19 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.