Whenever I type any “nonsense” command, this python error message is generated. Normal commands work fine. Any idea how to debug this?
$ somenonexistingcommand
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site.py", line 553, in <module>
main()
File "/usr/local/lib/python2.7/site.py", line 535, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/lib/python2.7/site.py", line 268, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/lib/python2.7/site.py", line 243, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/lib/python2.7/site.py", line 233, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/lib/python2.7/sysconfig.py", line 535, in get_config_var
return get_config_vars().get(name)
File "/usr/local/lib/python2.7/sysconfig.py", line 434, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/local/lib/python2.7/sysconfig.py", line 298, in _init_posix
raise IOError(msg)
IOError: invalid Python installation: unable to open /usr/include/python2.7/pyconfig.h (No such file or directory)
$ echo this works fine, however
this works fine, however
$
EDIT – after fixing my /usr/bin/python, I now get this different python error message:
$ yetanothernonexistingcommand
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 10, in <module>
import CommandNotFound
ImportError: No module named CommandNotFound
Somehow, python is being run whenever I mistype a command.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Ok, that makes things a bit clearer. command-not-found is a python program, which runs when your command is not something found on the system. (Its function is to suggest alternatives and corrections in case of mistyping etc.) See /usr/bin/command-not-found. It is trying to import the CommandNotFound module and is unable to, clearly pointing to a screwed up python installation. I’m not that familar with command-not-found, but I think fixing your Python installation will make the problem go away.
Just to elaborate a bit, what is probably happening is that the command-not-found module is located somewhere where your default python isn’t looking for it. A path problem, basically.
Debug suggestions:
-
To start with, what is the output from
$ type python
and what does package/installation does that file belong to?
-
What is the output for your installation corresponding to the code below? The path here is this python’s import path.
$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.import sys
sys.path
[”, ‘/usr/lib/python2.6’, ‘/usr/lib/python2.6/plat-linux2’, ‘/usr/lib/python2.6/lib-tk’, ‘/usr/lib/python2.6/lib-old’, ‘/usr/lib/python2.6/lib-dynload’, ‘/usr/local/lib/python2.6/dist-packages’, ‘/usr/lib/python2.6/dist-packages’, ‘/usr/lib/python2.6/dist-packages/PIL’, ‘/usr/lib/python2.6/dist-packages/gst-0.10’, ‘/usr/lib/pymodules/python2.6’, ‘/usr/lib/pymodules/python2.6/gtk-2.0’, ‘/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode’]
Method 2
I had this same error after installing Python 3.5.0 on my Ubuntu 14.04 LTS ( which has a system python of version 3.4.0).
After I opened the /usr/lib/command-not-found, I realized this error is due to system executing this script using the newly installed python3.5.0, because installing Python3.5.0 creates leads the system to use it when you type in python3.
This error can be easily corrected by changing the first line from
#!/usr/bin/python3
to
#!/usr/bin/python3.4
Method 3
I ran into this when I upgraded from the stock 2.6 that came with my ubuntu installation to the 3.2 python, with setting the default alternative to 3.2 rather than 2.6.
If you look at your /etc/bash.bashrc file there is a line that tells it to run this python script to look for alternatives in the repos. There is a package for it, however you cant remove the package once you’ve upgraded. I just simply moved the /usr/share/command-not-found and /usr/lib/command_not_found_handler and restarted my term and it works like good ol’ bash: command not found.
Method 4
The issue is with your $PATH environment variable. You’ve most likely messed it up. It should be similar to this:
$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
See this Linux Mint thread: http://forums.linuxmint.com/viewtopic.php?f=18&t=119561.
You can repair your $PATH in the shell with this command:
$ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
This is temporary! If the problem persists with a reboot then you’ve most likely hosed the $PATH in one of your environment setup files under /etc.
Method 5
The “command-not-found” package is a linux utility; it responds to unknown commands at the command shell prompt, not just within python sessions. (I see there is also a python package of this name.)
It has python among its dependencies, i.e. it uses python when triggered; so that accounts for why python is invoked whenever you type a command that the shell can’t find on your PATH.
I see there is an ‘apt’ package to install command-not-found in Linux; for Debian linux, this is cataloged at:
https://packages.debian.org/sid/admin/command-not-found
Method 6
Commenting out all the lines responsible for command-not-found in /etc/bash.bashrc solved the problem, which was created by switching Python versions.
Method 7
Just remove “command-not-found” using your package manager.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0