【问题标题】:Change Jupyter QtConsole settings更改 Jupyter QtConsole 设置
【发布时间】:2012-03-28 11:52:44
【问题描述】:

是否可以对 Windows 7 上的默认设置进行永久性更改? 我想更改字体大小和外壳大小。

【问题讨论】:

标签: python jupyter


【解决方案1】:

关于配置 ipython 命令行应用程序的说明是 IPython 网站上的here。特别是配置字体大小的分步说明:

首先,创建 IPython 配置文件。只需运行 IPython 或 IPython 的 QtConsole 即可为您完成此操作,但如果您必须手动操作,请运行

ipython profile create

其次,创建一个 IPython 配置文件:

  • Windows - %USERPROFILE%\.ipython\profile_default\ipython_config.py
  • Linux 或 OS X - ~/.ipython/profile_default/ipython_config.py

IPython 内容示例:

c = get_config()

c.IPythonWidget.font_size = 11
c.IPythonWidget.font_family = 'Consolas'

ipython.org 有更详细的示例配置文件。

【讨论】:

  • 最后一个链接现在已损坏,我认为ipython.org/ipython-doc/stable/config/index.html 是更新后的等价物。
  • @schodge - 已更新。谢谢! (将来,您可以随意提出修改建议,而不仅仅是添加评论。)
  • @JoshKelley ipython profile create 显示语法错误。
  • @AvinashRaj - 为我工作,所以我不知道出了什么问题。如果您仍然遇到问题,单独提出一个更详细的问题会比通过 cmets 讨论更容易。
  • 如果要改变初始窗口的大小,请使用c.IPythonWidget.height = 36,c.IPythonWidget.width = 96(值是指行数或列数)。
【解决方案2】:

适用于 linux:

使用https://bitbucket.org/joon/color-schemes-for-ipython-qt-console

pip install jupyter_qtconsole_colorschemes

~/.jupyter/jupyter_qtconsole_config.py, 您可以进一步配置此处提到的其他设置(https://jupyter.org/qtconsole/stable/config_options.html):

例子:

color_theme = 'monokai'  # specify color theme

import pkg_resources
c.JupyterQtConsoleApp.stylesheet = pkg_resources.resource_filename(
    "jupyter_qtconsole_colorschemes", "{}.css".format(color_theme))

c.JupyterWidget.syntax_style = color_theme
c.ConsoleWidget.font_size=15

【讨论】:

  • 对我来说,单独设置 c.JupyterWidget.syntax_style 是有效的。但是当同时设置c.JupyterQtConsoleApp.stylesheet时,它不起作用。
【解决方案3】:

使用最新版本的 IPython/Jupyter:

  1. 相关配置文件现在是~/.jupyter/jupyter_qtconsole_config.py

    在文件顶部我们做c = get_config()

  2. 字体大小相关命令为c.ConsoleWidget.font_size = 12

  3. (参见:a reference for the other configurable options。)

  4. 另一个设置是c.JupyterWidget.syntax_style = "trac"(例如),这是一个配色方案设置。 List of schemes。可以创建自定义方案:最简单的方法似乎是将your_name_here.py 放入$PYTHON/Lib/site-packages/pygments/styles 目录,格式与那里的其他文件类似。 (以这种方式配置听起来有点脆弱,但另一个 suggested way, of registering the custom scheme 似乎同样脆弱。)可以使用 CSS 指定更多样式。在上面的配置文件中:

    c.JupyterQtConsoleApp.stylesheet = '/path/to/your_name_here.css'
    

    here 给出了一个示例“LightBG”样式表。 (只有几个 CSS 类。一些默认突出显示仍然保持默认,无法使用 CSS 或 Pygments 样式文件更改它们。例如,SyntaxError 消息的突出显示保持默认. 这可能已在最新版本中修复 - 请参阅discussion here。)


这是一个奖金。使用一个函数调用更改 IPython qtconsole 设置的快捷方式。

将以下代码放入名为IPYTHON_PROFILE_DIR/startup/startup.ipy 的文件中。 (由于某种原因,它仍在~/.ipython 下,而不是~/.jupyter。)它可以命名为“startup.ipy”以外的名称,但扩展名必须是.ipy,而不是.py

def edit_config():
    profile_path = !ipython locate profile
    !{'gvim "%s/ipython_config.py"' % profile_path[0]}

(将“gvim”替换为您喜欢的编辑器。)

现在,每当您需要调整 Jupyter Qtconsole 配置时,您都可以使用:

In [1]: edit_config()

【讨论】:

  • 我使用的实际行是:!{'gvim -p "{0}/ipython_config.py" "{0}/../../.jupyter/jupyter_qtconsole_config.py" '.format(profile_path[0])} 这是在选项卡中打开两个配置文件。
  • 使用最新版本的 Anaconda Navigator 启动“qtconsole”时,c = get_config() 似乎会“挂起”控制台的启动。删除它并只使用变量c 就可以了。
【解决方案4】:

QtConsole 可以通过 ConsoleWidget 进行配置。开始:

> ipython qtconsole --ConsoleWidget.font_size=11

【讨论】:

  • 但是这些不是持久的变化,不像Josh的回答
【解决方案5】:
【解决方案6】:

一步一步,你会这样做:

在 Windows 7 (MingW) 下的 bash 中,我会直接从 IPython 获得帮助

/c/Python27/Scripts/IPython.exe qtconsole --help-all | grep font2.

然后您只需编辑 ipython_config.py(位于您的 .ipython 主目录中。在 Windows 7 中:/c/Users//.ipython/profile_default/ipython_config.py

c.IPythonWidget.font_size = 11
c.IPythonWidget.font_family = 'Calibri'

有关窗口大小,请查看此issue。您可能需要安装最新版本。

【讨论】:

    【解决方案7】:

    您可以右键单击 ipython 窗口并选择“默认”。您可以从那里设置默认配置。

    【讨论】:

      猜你喜欢
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      • 2017-05-23
      • 1970-01-01
      • 2017-01-17
      • 2016-01-18
      • 1970-01-01
      相关资源
      最近更新 更多