无法设置IPython提示符

无法设置IPython提示符,ipython,Ipython,我用以下内容运行ipython: c:\python27\scripts\ipython 出于某些原因,我正在尝试恢复旧的Python提示行为>>> 为此,我曾尝试在互联网上广泛搜索,但毫无结果 然后我接触了IPython文档,结果发现它既混乱又没有帮助。 据 要设置新提示,请将其指定给IPython外壳的“提示”属性: In [2]: ip = get_ipython() ...: ip.prompts = MyPrompt(ip) /home/bob >>> # it

我用以下内容运行ipython:

c:\python27\scripts\ipython
出于某些原因,我正在尝试恢复旧的Python提示行为>>>

为此,我曾尝试在互联网上广泛搜索,但毫无结果

然后我接触了IPython文档,结果发现它既混乱又没有帮助。 据

要设置新提示,请将其指定给IPython外壳的“提示”属性:

In [2]: ip = get_ipython()
...: ip.prompts = MyPrompt(ip)

/home/bob >>> # it works
我得到一个例外,即get_ipython未定义:

[TerminalIPythonApp] ERROR | Exception while loading config file C:\Users\xxx\.ipython\profile_default\ipython_config.py
Traceback (most recent call last):
File "c:\python27\lib\site-packages\traitlets\config\application.py", line 562, in _load_config_files
    config = loader.load_config()
  File "c:\python27\lib\site-packages\traitlets\config\loader.py", line 457, in load_config
    self._read_file_as_dict()
  File "c:\python27\lib\site-packages\traitlets\config\loader.py", line 489, in _read_file_as_dict
    py3compat.execfile(conf_filename, namespace)
  File "c:\python27\lib\site-packages\ipython_genutils\py3compat.py", line 278, in execfile
    exec(compiler(scripttext, filename, 'exec'), glob, loc)
  File "C:\Users\rgomulk\.ipython\profile_default\ipython_config.py", line 9, in <module>
    ip = get_ipython()
NameError: name 'get_ipython' is not defined
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
在下一轮谷歌搜索之后,我在配置中添加了以下行:

from IPython import get_ipython
这一次结果不同:

[TerminalIPythonApp] ERROR | Exception while loading config file C:\Users\xxx\.ipython\profile_default\ipython_config.py
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\traitlets\config\application.py", line 562, in _load_config_files
    config = loader.load_config()
  File "c:\python27\lib\site-packages\traitlets\config\loader.py", line 457, in load_config
    self._read_file_as_dict()
  File "c:\python27\lib\site-packages\traitlets\config\loader.py", line 489, in _read_file_as_dict
    py3compat.execfile(conf_filename, namespace)
  File "c:\python27\lib\site-packages\ipython_genutils\py3compat.py", line 278, in execfile
    exec(compiler(scripttext, filename, 'exec'), glob, loc)
  File "C:\Users\rgomulk\.ipython\profile_default\ipython_config.py", line 11, in <module>
    ip.prompts = MyPrompt(ip)
AttributeError: 'NoneType' object has no attribute 'prompts'
因此,问题有两个方面: 1.如何实际设置提示/恢复旧的提示行为? 2.为什么IPython文档中的代码不起作用?这是实现或文档中的错误吗

IPython版本和IPython输出中已给出的其他版本

问候,,
Robert

经过广泛的搜索,它真的很乏味,其他人也很困惑,特别是在区分启动脚本和配置脚本时,我发现了以下页面:

这导致了工作解决方案:

from IPython.terminal.prompts import Prompts
from pygments.token import Token

class MyPrompt(Prompts):
    def in_prompt_tokens(self, cli=None):
        return [(Token.Prompt, '>>> ')]

c.TerminalInteractiveShell.prompts_class = MyPrompt
请注意,官方文件似乎没有要求:

文件通常从获取根配置对象开始:

c=获取配置

问候,


Robert

经过广泛的搜索,它真的很乏味,其他人也很困惑,特别是在区分启动脚本和配置脚本时,我发现了以下页面:

这导致了工作解决方案:

from IPython.terminal.prompts import Prompts
from pygments.token import Token

class MyPrompt(Prompts):
    def in_prompt_tokens(self, cli=None):
        return [(Token.Prompt, '>>> ')]

c.TerminalInteractiveShell.prompts_class = MyPrompt
请注意,官方文件似乎没有要求:

文件通常从获取根配置对象开始:

c=获取配置

问候,


Robert

另一种可能性(不太通用)是使用预定义的提示类:

from IPython.terminal.prompts import ClassicPrompts

c = get_config()

c.TerminalInteractiveShell.prompts_class = ClassicPrompts

另一种可能性(不太通用)是使用预定义的提示类:

from IPython.terminal.prompts import ClassicPrompts

c = get_config()

c.TerminalInteractiveShell.prompts_class = ClassicPrompts

请注意,此方法不再有效,iPython在一段时间前更改了配置处理最后一行现在应为c.InteractiveShell.prompts_class=MyPrompt`请注意,此方法不再有效,iPython在一段时间后更改了配置处理最后一行现在应为c.InteractiveShell.prompts_class=MyPrompt`