When you run a command
foo is replaced by whatever command you're running), the shell searches all the directories in the
PATH environment variable for a file called
foo with execute permissions.
If it doesn't find it, then in an Ubuntu system with the default configuration, it runs the command
/usr/lib/command-not-found foo. This is done at the
That's what produces output like:
No command 'foo' found, did you mean:
Command 'fio' from package 'fio' (universe)
Command 'goo' from package 'goo' (universe)
Command 'fop' from package 'fop' (main)
Command 'fox' from package 'objcryst-fox' (universe)
Command 'xoo' from package 'xoo' (universe)
Command 'zoo' from package 'zoo' (universe)
foo: command not found
The program 'gnuchess' is currently not installed. You can install it by typing:
sudo apt-get install gnuchess
command-not-found program itself (i.e.,
/usr/lib/command-not-found) is a Python script:
$ file /usr/lib/command-not-found
/usr/lib/command-not-found: a /usr/bin/python script text executable
So if your Python installation is broken, it is expected that
command-not-found will always fail and give an error about Python. You can fix the problem by fixing your Python installation.
Ubuntu comes with Python installed, and requires Python for numerous programs (like the Update Manager and the Software Center, for example). Various different versions of Python are simultaneously available through the official software sources and different versions can be installed simultaneously without conflict. However, it is also possible to install Python manually by building it from source. If you do that, it's up to you to make sure that your manually compiled and installed Python does not conflict with any other installed Python implementations.
So the first thing you should do is to uninstall any manually installed Python. When installing it, there is a directory in which you would have run the command
sudo make install. You need to go to that directory and run
sudo make uninstall.
After you've removed all manual Python installations (if any), then completely reinstall Python:
sudo apt-get update
sudo apt-get --purge --reinstall install python
That will probably work. If it doesn't, then please provide the output of:
which -a python
file /usr/bin/python /usr/bin/python2.7