ipython 配置

警告
本文最后更新于 2022-09-13,文中内容可能已过时。

通过配置 ipython 以获得更好的编辑体验。

prompt 设置

配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
~/anaconda3/bin/ipython profile create

[ProfileCreate] Generating default config file: '/home/william/.ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: '/home/william/.ipython/profile_default/ipython_kernel_config.py'

cd ~/.ipython/profile_default/
vim ipython_config.py


## 修改颜色
## Set the color scheme (NoColor, Neutral, Linux, or LightBG).
#  Choices: any of ['Neutral', 'NoColor', 'LightBG', 'Linux'] (case-insensitive)
#  Default: 'Neutral'
# c.InteractiveShell.colors = 'Neutral'
c.InteractiveShell.colors = 'NoColor'

或者启动的时候指定颜色方案

1
~/anaconda3/bin/ipython --colors=NoColor

或者运行时设置

1
[1] %colors nocolor

定制配置

在 ``~.ipython/profile_default/ipython_config.py` 添加

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# ~/anaconda3/bin/ipython profile create
# vim ~/.ipython/profile_default/ipython_config.py
from IPython.terminal.prompts import Prompts, Token
import os

class MyPrompt(Prompts):
    def in_prompt_tokens(self, cli=None):   # custom
        path = os.path.basename(os.getcwd())
        user = os.environ['USER']
        return [
            (Token.Prompt, ''),
            (Token.PromptNum, f"{path}❯ "),
            (Token.Prompt, 'In ['),
            (Token.PromptNum, str(self.shell.execution_count)),
            (Token.Prompt, ']'),
            (Token.Prompt, ': '),
        ]

## ====================================================
c = get_config()
c.TerminalInteractiveShell.prompts_class = MyPrompt
c.InteractiveShell.colors = 'NoColor'
c.TerminalIPythonApp.display_banner = False
## ====================================================


""" 如果需要运行时设置,可以使用以下命令
ip = get_ipython()
ip.prompts = MyPrompt(ip)
"""

相关内容

william 支付宝支付宝
william 微信微信
0%