Snow Leopard, Python Tab Completion
Thursday, 10 Mar, 2011Usually (meaning in Linux distributions), all it takes to have tab completion in python's interactive interpreter, is to create a ~/.pythonrc in your home dir, and include it in your ~/.bashrc or ~/.bash_profile like so export PYTHONSTARTUP=~/.pythonrc:
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
This doesn't work by default for us Snow Leopard users, because the distributed readline.so doesn't have those capabilities. So, we need to install a more robust version of it:
sudo pip install readline
even if you pip/easy_install readline, which has the capability to tab complete, the system file readline.so takes precedence over the installed one.
To fix this you need to:
cd /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/
sudo mv readline.so readline.so.default
sudo cp /Library/Python/2.6/site-packages/readline.so .
Now, not sure if a future system upgrade will overwrite this, but apple usually upgrades python stuff in major revisions. Should be safe ’till Lion.
Comments
Comments for this entry are closed. If you wish to further discuss this post, please contact us directly.