如何在OSX中的python repl中为历史搜索进行键绑定?
我在linux中使用了下面的pystartup脚本,以便在REPL Python中提供选项卡上的历史记录和自动完成。我已经切换到OSX,并修改了脚本,使选项卡完成工作。但我不知道如何使搜索工作?搜索几个这样的问题 但是我不想卸载OSX附带的python版本,因为它可能会导致其他一些依赖关系中断 我的python版本是2.7.10 剧本如何在OSX中的python repl中为历史搜索进行键绑定?,python,macos,Python,Macos,我在linux中使用了下面的pystartup脚本,以便在REPL Python中提供选项卡上的历史记录和自动完成。我已经切换到OSX,并修改了脚本,使选项卡完成工作。但我不知道如何使搜索工作?搜索几个这样的问题 但是我不想卸载OSX附带的python版本,因为它可能会导致其他一些依赖关系中断 我的python版本是2.7.10 剧本 import atexit import os import readline import rlcompleter historyPath = os.pat
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
您不需要卸载Mac OSX python。您应该只安装可以与系统python共存的新python 使用下面的命令安装Python2.7.X
brew install python@2
使用下面的命令安装Python3.6.X
brew install python
如果您没有brew,请按照上提到的相同步骤进行设置
一旦你这样做,它将自动工作
该脚本与High Sierra 10.13.4上的系统python配合使用;我还可以确认它是使用readline支持构建的:
$python-c“导入readline;打印(readline.\uu文件)”
返回/System/Library/Frameworks/python.framework/Versions/2.7/lib dynload/readline.so
,$python-c“导入readline;打印(readline.\uu文件)”| xargs otool-L
显示它与libedit
和libncurses
链接。你有什么MacOS版本?还有,你把脚本放在哪里?它的路径正确吗?我的是$python-c“导入站点;打印(site.getusersitepackages())”|xargs-I{}ls{}/sitecustomize.py
,它返回/Users/hoefling/Library/python/2.7/lib/python/site-packages/sitecustomize.py
,在我的机器上。顺便说一句,你无论如何都不能完全卸载系统python,至少不能不关闭SIP,所以我不在乎这个。我有很高的塞拉山。在塔伦给出答案后,我能够得到历史搜索。问题在于virtualenv指向系统python。