I have a problem with my "b" letter in Python shell in OS X. I can't type "b", but "B" worked fine.

How can I solve this issue?

| improve this question | | | | |
  • What do you mean by "can't type"? Something physically stops you from pressing the b key unless you also press Shift? Or there's no effect from pressing the button? Or you get some error message when you line that contains only "b"? – Joachim Sauer Jun 14 '11 at 12:12
  • What exactly? What exactly are you doing/typing in, what exactly happens and what exactly is the error message (if there is one)? – delnan Jun 14 '11 at 12:12
  • If no other letters are affected, it sounds like a hardware problem with your keyboard and should be migrated to Super User. – pavium Jun 14 '11 at 12:14
  • When pressing "b" letter don't any effect and don't type "b" letter but when I pressing "B" letter (Shift + b) then "B" letter type in console – Mohammad Javad Mahmoudi Jun 14 '11 at 12:16
  • 2
    See also this question. – Keith Thompson Aug 19 '11 at 16:36

The problematic line in your .pythonstartup is something like:

 readline.parse_and_bind("bind ^I rl_complete") # darwin libedit

This .pythonstartup will fix it...

    import readline
except ImportError:
    print "Module readline not available."
    import rlcompleter
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
        readline.parse_and_bind("tab: complete")
| improve this answer | | | | |
  • that did solve the same issue for me ! – zmo May 25 '12 at 16:53
  • +1 I just installed python from homebrew yesterday and ran into this problem this morning. Updated my python startup file and everything is good again. It's a very specific (and extremely odd) side effect. – Seth Mar 7 '15 at 19:21

First, this did not happen until I updated python 2.7.1 to 2.7.3. That said, the fix is on the line:

old line:

if(sys.platform == 'darwin'): #FIX

new line:

if(sys.platform == 'darwin') and 'libedit' in readline.__doc__: #FIX

The full code in my ~/.pythonrc

import atexit
import os
    import readline
except ImportError:
    print "Module readline not available."
    import rlcompleter
    import sys
    if(sys.platform == 'darwin') and 'libedit' in readline.__doc__: #FIX
    # OSX
        readline.parse_and_bind ("bind ^I rl_complete")
    # Linux
        readline.parse_and_bind("tab: complete")

historyPath = os.path.expanduser("~/.pyhistory")

def save_history(historyPath=historyPath):

if os.path.exists(historyPath):

del atexit, save_history, historyPath
| improve this answer | | | | |

I have the same issue. This happens when you use the MacPorts version of Python in Snow Leopard.

I don't see this issue in Apple's Python that comes with Mac OS X. So, the workaround should be to set PYTHONPATH pointing to MacPorts' packages:


(or a different Python version) and use Apple's Python.

| improve this answer | | | | |

Unfortunately, the workaround is not a wise one.

Apple assumes that its version is unchanged when doing upgrades and other functions. Instead, it is recommended that if you wish to upgrade python or expand it that you install a local version, either under /opt or your home folder.

I also have the same problem, and I do not use the MacPorts version of python.

I am using the latest version of vpython, visual python, from www.vpython.org under Mac OX X Lion running in the latest MacBook Air (generation 3).

I installed vpython using their latest binary and using their instructions. It comes with an installer so it is point and click. This is a modified version of Python 2.7.1. It is 32 bit version. (I believe they have not ported it to 64 bits). I then installed VPython-Mac-Py2.7-5.71. I followed this by scipy from www.scipy.org and matplotlib from matplotlib.sourceforge.net All of these installations use an installer.

When I run python off their development tool, idle, or the vpython variant, vidle, I have no problems. If I open a terminal and run python from a bash shell, the shell will not recognize the "b" key in the keyboard. It will give you a 'bell' sound, instead of typing the 'character b'. However, you can enter the letter 'B'. Looks like this key is mapped to some incorrect non-displayed 'character', possibly the 'bell' character in old ASCII code.

I tried changing the emulation to xterm, vt100, vt102. I also played with different encoding schemes like just using UTF-8. I also pressed different combination of special keys like command-b etc. Nothing worked.

My only workaround is to write scripts off idle or vidle.

I hope this helps clarify the problem.

| improve this answer | | | | |
  • I worked a bit more on this... looks like others have similar problems with other python interfaces. In my system I have a .pythonrc.py file that is parsed when python starts (pointed to by PYTHONSTARTUP). In this file two modules are loaded rlcompleter and readline. It then calls readline.parse_and_bind("bind -v"). This call initilizes the readline module by copying the bindings from the shell (you can see yours by going into the bash shell and typing 'bind -v' (no quotes)). One of these must creat the problem. If I comment the line (place # in front of it.), the problem disappears. – g a mercier Oct 1 '11 at 11:10
  • 1
    You can edit your post to include that, might make it easier to read. – slhck Oct 1 '11 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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