1

I just installed Ubuntu 18.04.4 LTS on Windows under Windows Subsystem For Linux (WSL). When I run a command that doesn't exist in my bash terminal (for example if I accidentally add an extra s to ls), I get this error:

$ lss
-bash: /usr/bin/python: No such file or directory

The error's right, I only have python3 installed:

$ ls /usr/bin/python*
/usr/bin/python3           /usr/bin/python3-jsonpatch    /usr/bin/python3-jsonschema  /usr/bin/python3.6m
/usr/bin/python3-jsondiff  /usr/bin/python3-jsonpointer  /usr/bin/python3.6           /usr/bin/python3m

From previous use of Ubuntu, I remember that the message should be "The program 'lss' can be found in the following packages:" I don't need that message anymore and I don't want to install python2 just to get it working (this question has answers for solving the problem by installing py2).

Is it possible to fix this without installing python2, symlinking python 3 as 2, or becoming perfect and never making typos again?

Ideally, I could port the "command doesn't exist" script to python3 or disable it completely.

2 Answers 2

0

Python3 is not a drop in replacement for python2. You need a python3 version of lss.

I would update lss if I was you. It is a stand-alone script and the source can be found on github. 1 is obvious:

print 'Usage:', __file__, '/path/to/dir'

"print" needs to use "(" and ")" when using python3. I would put the script in a file named lss3 or something like that and use python3 lss3 to find and fix errors.

1
  • Sorry for the confusion. lss was a throwawy example. I'm talking about every single invalid command I enter. If I typo a command (like lss or aptatude) or use something that I haven't yet installed (eclipse), I get that error. On older versions of ubuntu, it would tell me what package to install to get that command.
    – idbrii
    Mar 23, 2020 at 21:40
0

Turns out I was overriding the command_not_found_handle function (a bash feature) with something that called python directly in my bashrc:

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found ]; then
    function command_not_found_handle {
        # check because c-n-f could've been removed in the meantime
        if [ -x /usr/lib/command-not-found ]; then
           /usr/bin/python /usr/lib/command-not-found -- $1
           return $?
        else
           return 127
        fi
    }
fi

This code is no longer necessary (was it ever?) and removing it fixed my problem -- now the old "can be found in the following packages" output again.

For completeness: If I wanted to skip the python code and simple output that the command doesn't exist, I could put this in my bashrc:

function command_not_found_handle {
    echo Command not found: $1
    return 127
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .