python 选项卡完成 Mac OSX 10.7 (Lion) [英] python tab completion Mac OSX 10.7 (Lion)

查看:68
本文介绍了python 选项卡完成 Mac OSX 10.7 (Lion)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在升级到 Lion 之前,我通过终端在 python shell 中完成了选项卡工作.按照这些说明,可以使选项卡完整工作.

Before upgrading to lion, I had tab complete working in a python shell via terminal. Following these instructions, it was possible to have tab complete working.

自从升级到 Lion 后,我现在无法在 Python 的终端会话中完成选项卡的工作.我已按照上述说明操作,但仍然无法正常工作.

Since upgrading to Lion, I am now unable to get tab complete working in a terminal session of Python. I've followed the above instructions to the letter, and it still does not work.

Lion 中的 readline 模块有区别吗?连接到 'tab:complete' 选项似乎不再起作用.我想知道是终端忽略了 readline,还是 python 本身.

Is there a difference with the readline module in Lion? Hooking in to the 'tab:complete' option no longer seems to work. I'm wondering if it is terminal that is ignoring readline, or if it is python itself.

Python 版本:2.7.1

Python version: 2.7.1

通过选项卡完成,我的意思是我可以执行以下操作:

By tab complete, I mean I could do something like the following:

# django
import MyModel
MyModel.objects.a[TAB] # will complete to all()

推荐答案

Apple 没有随 OS X 提供 GNU readline.它提供 BSD libedit 包括一个 readline 兼容性接口.Apple 提供的系统 Python 和来自 python.org 安装程序的 64 位/32 位 Python 是使用 libedit 构建的.问题是 libedit 支持的命令与 readline 支持的命令完全不同(参见例如讨论 此处).传统的仅限 32 位的 python.org 安装程序确实使用 GNU readline,就像其他一些适用于 OS X 的 Python 3rd-party 发行商一样,例如 MacPorts.很有可能你以前使用过这样的 Python 而不是最近的 Apple .除了修改 Django 之外,您还有一些选择:您可以安装第三方替换 readline 模块;或者您可以使用 GNU readline 附带的另一个 Python.但是,您不应该在 10.7 上使用仅 32 位的 python.org Python,因为不幸的是,10.7 上的 Xcode 4 不再包含那些 Python 需要的 gcc-4.0 和 OS X 10.4u SDK使用 C 扩展模块构建和安装包.

Apple does not ship GNU readline with OS X. It does ship BSD libedit which includes a readline compatibility interface. The system Pythons shipped by Apple and the 64-bit/32-bit Pythons from python.org installers are built with libedit. The problem is that the commands supported by libedit are completely different from those of readline (see for example the discussion here). The traditional 32-bit-only python.org installers do use GNU readline as do some other 3rd-party distributors of Python for OS X, like MacPorts. Chances are that you were previously using such a Python and not a recent Apple one. You do have a few options, besides modifying Django: you can install the third-party replacement readline module; or you can use another Python that comes with GNU readline. However, you should not use the python.org 32-bit-only Pythons on 10.7 because, unfortunately, Xcode 4 on 10.7 no longer includes gcc-4.0 and the OS X 10.4u SDK which those Pythons need to build and install packages with C extension modules.

将以下内容放入 python 启动文件中,将为 libedit 界面和典型的 readline 模块启用 Tab 补全.有关 python 启动文件的更多信息,参见此处

Putting the following in the python startup file will enable tab completion for both the libedit interface and the typical readline module. For more information on the python startup file, see here

import readline
import rlcompleter
if 'libedit' in readline.__doc__:
    readline.parse_and_bind("bind ^I rl_complete")
else:
    readline.parse_and_bind("tab: complete")

这篇关于python 选项卡完成 Mac OSX 10.7 (Lion)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆