Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jun 15 '11 at 12:55

This question came from our site for professional and enthusiast programmers.

    
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
1  
See also this question. –  Keith Thompson Aug 19 '11 at 16:36

4 Answers 4

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
try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
    import sys
    if(sys.platform == 'darwin') and 'libedit' in readline.__doc__: #FIX
    # OSX
        readline.parse_and_bind ("bind ^I rl_complete")
    else:
    # Linux
        readline.parse_and_bind("tab: complete")

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

def save_history(historyPath=historyPath):
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

atexit.register(save_history)
del atexit, save_history, historyPath
share|improve this answer

The problematic line in your .pythonstartup is something like:

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

This .pythonstartup will fix it...

try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")
share|improve this answer
    
that did solve the same issue for me ! –  zmo May 25 '12 at 16:53

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.

share|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

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:

/opt/local/lib/python/site-packages:/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 

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

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.