-1

我在 linux 中使用下面的 pystartup 脚本来使 REPL Python 中的选项卡上的历史记录和自动完成功能可用。我已经切换到 OSX 并且我已经修改了脚本,以便选项卡完成工作。但我无法弄清楚如何使搜索工作?搜索几个 SO 问题,例如 Python 交互模式历史和箭头键

但我不想卸载 OSX 附带的 python 版本,因为它可能会导致其他一些依赖关系破坏。

我的 python 版本是 2.7.10

脚本

import atexit
import os
import readline
import rlcompleter

historyPath = os.path.expanduser("~/.pyhistory")

def save_history(historyPath=historyPath):
    import readline
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

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

readline.set_history_length(1000)
atexit.register(readline.write_history_file, historyPath)

atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
4

1 回答 1

1

你不需要卸载 Mac OSX python。您应该只安装可以与系统 python 共存的新 python。

使用下面安装 Python 2.7.X

brew install python@2

使用下面安装 Python 3.6.X

brew install python

如果你没有 brew 然后设置相同的以下步骤

https://brew.sh

一旦你这样做,它会自动工作

阅读线默认值

于 2018-05-11T10:22:14.710 回答