The documentation of the Python readline
module says "Availability: Unix". However, it doesn't appear to be available on OS X, although other modules marked as Unix are available. Here is what I'm using:
Python readline模块的文档说“可用性:Unix”。但是,它似乎在OS X上不可用,尽管可以使用标记为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 >>>
I have also installed Python 2.5 through MacPorts but readline
is not available there either.
我也通过MacPorts安装了Python 2.5,但也没有readline。
What can I do to provide readline
functionality for Python's raw_input()
function on OS X?
如何在OS X上为Python的raw_input()函数提供readline功能?
4 个解决方案
#1
7
Have you tried to install the py-readline
(or py25-readline
for Python 2.5) port?
您是否尝试安装py-readline(或Python 2.5的py25-readline)端口?
Also, in the snippet above, you are NOT using the MacPort python, but rather the Apple Python.
此外,在上面的代码片段中,您不是使用MacPort python,而是使用Apple Python。
The MacPort version should be located in the /opt/local
directory structure. You should check your path.
MacPort版本应位于/ opt / local目录结构中。你应该检查你的路径。
#2
4
Try rlwrap
. It should work with any version of python and in general any shell.
试试rlwrap。它应该适用于任何版本的python,并且通常适用于任何shell。
Install via brew install rlwrap
on Mac OS X
在Mac OS X上通过brew install rlwrap安装
usage as rlwrap python
. It stores history as well.
用作rlwrap python。它也存储历史。
#3
3
It's not shipped in OS X because of licensing issues (restrictions brought to you by the GPL).
由于许可问题(GPL为您带来的限制),它不会在OS X中提供。
Macports python should be fine if you have the readline package installed.
如果安装了readline包,Macports python应该没问题。
#4
3
You should be able to get readline support on Mac's native Python. Apparently it's implemented via BSD's editline, and you have to start it up slightly differently. I just tested this on a Mac, and it works fine (OS X 10.5.7). See man python
for more details, the section "Interactive Input Editing and History Substitution" - mirrored on the web here.
你应该能够在Mac的原生Python上获得readline支持。显然它是通过BSD的编辑线实现的,你必须以稍微不同的方式启动它。我刚在Mac上测试过它,它运行正常(OS X 10.5.7)。有关详细信息,请参阅man python,“交互式输入编辑和历史替换”部分 - 在此处在Web上进行了镜像。
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
>>>
#1
7
Have you tried to install the py-readline
(or py25-readline
for Python 2.5) port?
您是否尝试安装py-readline(或Python 2.5的py25-readline)端口?
Also, in the snippet above, you are NOT using the MacPort python, but rather the Apple Python.
此外,在上面的代码片段中,您不是使用MacPort python,而是使用Apple Python。
The MacPort version should be located in the /opt/local
directory structure. You should check your path.
MacPort版本应位于/ opt / local目录结构中。你应该检查你的路径。
#2
4
Try rlwrap
. It should work with any version of python and in general any shell.
试试rlwrap。它应该适用于任何版本的python,并且通常适用于任何shell。
Install via brew install rlwrap
on Mac OS X
在Mac OS X上通过brew install rlwrap安装
usage as rlwrap python
. It stores history as well.
用作rlwrap python。它也存储历史。
#3
3
It's not shipped in OS X because of licensing issues (restrictions brought to you by the GPL).
由于许可问题(GPL为您带来的限制),它不会在OS X中提供。
Macports python should be fine if you have the readline package installed.
如果安装了readline包,Macports python应该没问题。
#4
3
You should be able to get readline support on Mac's native Python. Apparently it's implemented via BSD's editline, and you have to start it up slightly differently. I just tested this on a Mac, and it works fine (OS X 10.5.7). See man python
for more details, the section "Interactive Input Editing and History Substitution" - mirrored on the web here.
你应该能够在Mac的原生Python上获得readline支持。显然它是通过BSD的编辑线实现的,你必须以稍微不同的方式启动它。我刚在Mac上测试过它,它运行正常(OS X 10.5.7)。有关详细信息,请参阅man python,“交互式输入编辑和历史替换”部分 - 在此处在Web上进行了镜像。
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
>>>