Snow Leopard, Python Tab Completion

Πέμπτη, 10 Μάρ, 2011 - python

Usually (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.

Σχόλια

Ο σχολιασμός έχει κλείσει. Εάν θέλετε να συζητησετε περαιτέρω περί αυτής της ανάρτησης, παρακαλώ επικοινωνήστε μαζί μας.