Ubuntu 18.04 (WSL) problems with Python 3.7.4

by Joe Paris   Last Updated September 12, 2019 03:02 AM

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:

[email protected]:~$ 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.

[email protected]:~$ 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
[email protected]:~$ 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.

Related Questions

Unexpected suggestions on shell

Updated September 29, 2018 05:02 AM

Install pygtk on bash on WSL

Updated July 28, 2018 23:02 PM

How to display a python animation in bash terminal

Updated August 21, 2018 10:02 AM