Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I think I messed something up on my Ubuntu server while trying to upgrade to Python 2.7.2. Every time I type in a command that doesn't have a response, the default from bash is this:

-bash: /usr/bin/python: is a directory

Just like it would say if I typed the name of a directory. But this happens every time I enter a command that doesn't do anything.

artur@SERVER:~$ dslkfjdsklfdshjk
-bash: /usr/bin/python: is a directory

I remember messing with the update-alternatives to point at python at some point, perhaps that could be it? Any inklings as to why this is happening?

Related to this problem is also the fact that when I try using easy_install it tells me

-bash: /usr/bin/easy_install: /usr/bin/python: bad interpeter: Permission denied

/etc/fstab/ is set to exec. I've read that could fix the second problem but it hasn't.

share|improve this question
add comment

1 Answer 1

When you run a command foo (where 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. That's what produces output like:

ek@Apok:~$ foo
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

And:

ek@Apok:~$ gnuchess
The program 'gnuchess' is currently not installed.  You can install it by typing:
sudo apt-get install gnuchess

The command-not-found program itself (i.e., /usr/lib/command-not-found) is a Python script:

ek@Apok:~$ 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

share|improve this answer
    
Thank you so much for such an elaborate answer. The thing is I've been trying to install 2.7.2 with Pythonbrew. I'll try your method and get back to you. –  Artur Sapek Nov 13 '11 at 3:57
    
Pythonbrew builds and installs Python in your home directory, which shouldn't change anything about /usr/bin/python. However, it does seem an odd coincidence that you have this problem on a system with a Pythonbrew installation of Python. –  Eliah Kagan Nov 13 '11 at 18:07
    
WOW Great answer –  user8290 Dec 9 '11 at 23:54
add comment

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.