Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
1  
@ripper: Interesting. A few stray observations. Does your .bashrc have anything connected with python in it? Do you get this same behavior with other user accounts? Why do you have python 2.7 installed locally? What is the default official python on this installation, and if not 2.7, do you have it installed? What ubuntu version is this? –  Faheem Mitha Mar 18 '11 at 19:02
    
@Faheem - I don't see anything python related in .bashrc. I installed python locally myself. I know the machine has two other pythons installed as well. I have Ubuntu 10.10 installed. –  ripper234 Mar 18 '11 at 19:07
    
This smells a bit like a python installation gone astray. What are the versions official system pythons installed, and why did you install 2.7 locally? Is it not one of the officially available versions? –  Faheem Mitha Mar 18 '11 at 19:11
    
@Faheem - I don't understand your question. What do you mean by "official"? I needed python 2.7, so I installed it. I am the admin of this box. I installed python by doing make/make install, didn't do anything fishy (I think). –  ripper234 Mar 18 '11 at 19:16
    
@ripper: Meaning, ubuntu provided it as a binary package. When you type python, which python do you get? –  Faheem Mitha Mar 18 '11 at 19:19

4 Answers 4

up vote 8 down vote accepted

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:

1) To start with, what is the output from

$ which python

and what does package/installation does that file belong to?

2) 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']
share|improve this answer
1  
one possible solution is # apt-get remove command-not-found... –  simon Mar 19 '11 at 3:41
    
"Screwed up python installation" - any idea what exactly is missing. Is CommandNotFound a core python module, or can/should I install it separately? –  ripper234 Mar 19 '11 at 14:19
    
@ripper: CommandNotFound is part of the command-not-found package, which must be installed on your machine already, else you wouldn't be seeing this message. However, you could easily verify that by querying the package manager. dpkg -l command-not-found . Your problem is that your default python installation is not seeing this module. I'll add some steps to debug above. Others please feel free to modify & correct. –  Faheem Mitha Mar 19 '11 at 15:31
    
See this followup question - unix.stackexchange.com/questions/9711/… –  ripper234 Mar 20 '11 at 8:03

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.

share|improve this answer
3  
If you want to disable the command_not_found handler, don't mess with /usr (that can make subsequent upgrades fail or be undone by subsequent upgrades). Instead, change /etc/bash.bashrc. Or disable this in your own ~/.bashrc with unset -f command_not_found_handle. –  Gilles Jul 4 '11 at 8:31

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.

share|improve this answer

Commenting # all lines responsible for command-not-found in /etc/bash.bashrc solved problem, wich was created by switching python versions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.