代码之家  ›  专栏  ›  技术社区  ›  Greg Hewgill

为什么Python readline模块在OS X上不可用?

  •  4
  • Greg Hewgill  · 技术社区  · 17 年前

    Python的文档 readline 模块显示“可用性:Unix”。但是,它似乎在OSX上不可用,尽管标记为Unix的其他模块也可用。以下是我正在使用的:

    $ uname -a
    Darwin greg.local 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386
    $ which python
    /usr/bin/python
    $ python
    Python 2.3.5 (#1, Nov 26 2007, 09:16:55) 
    [GCC 4.0.1 (Apple Computer, Inc. build 5363) (+4864187)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import readline
    Traceback (most recent call last):
      File "", line 1, in ?
    ImportError: No module named readline
    >>> 
    

    我还通过MacPorts安装了Python 2.5,但是 阅读线 那里也没有。

    阅读线 Python的功能 raw_input() OSX上的函数?

    4 回复  |  直到 17 年前
        1
  •  7
  •   tegbains    17 年前

    您是否已尝试安装 py-readline (或 py25-readline

    此外,在上面的代码片段中,您使用的不是MacPort python,而是Apple python。

    MacPort版本应位于 /opt/local

        2
  •  5
  •   Sairam    9 年前

    尝试 rlwrap . 它应该适用于任何版本的python,通常也适用于任何shell。

    brew install rlwrap 在MacOSX上

    rlwrap python . 它也存储历史。

        3
  •  4
  •   Dustin    17 年前

    由于许可问题(GPL带来的限制),它没有在OSX中发布。

        4
  •  3
  •   Telemachus MrJames    16 年前

    您应该能够在Mac的本机Python上获得readline支持。显然,它是通过BSD的编辑行实现的,您必须以稍微不同的方式启动它。我刚刚在Mac上测试了这个,它运行良好(OSX10.5.7)。看见 man python mirrored on the web here .

    luga ~ $ python 
    Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12) 
    [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import rlcompleter
    >>> import readline
    >>>
    
    推荐文章