ChatGPT解决这个技术问题 Extra ChatGPT

更改 Jupyter Notebook 中的主题?

我喜欢黑暗的主题。但是,Jupyter 笔记本的默认主题是浅色的,我找不到更改主题/背景颜色的选项。这是怎么做到的?

使用 JupyterLab:设置 -> JupyterLab 主题 -> JupyterLab Dark

S
Shayan Shafiq

使用 Kyle Dunovan 的 jupyter-themes 包很容易做到这一点。您可以使用 conda 安装它。否则,您将需要使用 pip

使用 conda 安装它:

conda install -c conda-forge jupyterthemes

或点:

pip install jupyterthemes

您可以通过以下方式获取可用主题列表:

jt -l

所以改变你的主题:

jt -t theme-name

最后,要加载主题,重新加载页面。文档和源代码是 here


注意 - 我必须重新启动 jupyter 服务器才能使其正常工作。
第一次可能需要重新启动 jupyter notebook 才能工作,但下一次,只需在终端上更改 jt -t <themes> 并重新加载笔记本页面。它对我来说是这样的。
jupyterthemes 不在 conda 上,也不在 conda-forge 上,安装它的唯一方法是仅通过 pip
添加 conda-forge 频道 conda config --add channels conda-forge 后,我确实成功使用了 conda
如果 jupyterthemes 在 conda-forge 上,答案应该是 `conda install jupyterthemes -c conda-forge
F
François Noël

按着这些次序

使用 pip 安装 jupyterthemes

pip install jupyterthemes

然后从以下选择主题并使用以下命令进行设置,一旦安装成功,我们中的许多人认为我们需要再次启动 jupyter 服务器,只需刷新页面即可。

使用以下命令设置主题:

jt -t <theme-name>

可用主题:

独角兽

三年级

海洋16

胸怀

物开

日晒

日晒

Github repository 中还提供了可用主题的屏幕。


列出了两件事:1.对启动jupyter服务器的歧视。 2. 主题连词/名称
这并不真正需要一个新的答案。只是对现有的一个小修改。
this 还有一个 chrome 扩展程序。它基本上做同样的事情,但没有终端交互。
经典主题的名字是什么?如果我想恢复并回到原来的经典?
为了完整起见,除了列出的主题之外,这 2 个主题也可用:gruvboxd、gruvboxl,截至 2019 年 1 月
N
Natheer Alabsi

在我更改主题后,它的行为很奇怪。字体很小,看不到工具栏,我真的不喜欢新的外观。

对于那些想要恢复原始主题的人,您可以执行以下操作:

jt -r

您需要在第一次执行 Jupyter 时重新启动它,稍后刷新足以启用新主题。

或直接从笔记本内部

!jt -r

谢谢!我同意不喜欢它,下面的选项建议将深色阅读器添加到 chrome 中更好
S
Shayan Shafiq

我建议您在 Chrome 中使用“Dark Reader”extension,而不是在 Jupyter 中安装库(您可以在其他浏览器中找到“Dark Reader”扩展程序,例如 Firefox)。你可以玩它;过滤您想要使用深色主题的 URL,甚至是如何为自己定义深色主题。下面是几个例子:

https://i.stack.imgur.com/PBqOq.png

https://i.stack.imgur.com/ZtvSr.png

我希望它有所帮助。


我认为这是最好的方法,因为我们通常需要它提供的深色主题,此外,只需单击即可轻松检查我们正在创建的文档的真实视觉效果。 (在发布时很重要)
是的……这一切都很好,但是黑暗阅读器不知道 jupyter 笔记本应该给单词着色。没有语法着色,这使得这个选项成为禁忌。
@darlove,就我使用它而言,那里有一个“语法着色”(例如,“for loop”语法在整个代码中具有相同的颜色。
不过有一个问题。如果您尝试使用鼠标选择几个字符,则选择在黑色背景上不可见。
一开始我也遇到了代码没有突出显示或分类的问题。您需要将模式从动态更改为过滤器或过滤器+。这显着改变了黑暗读者的行为。
A
Amir F

您可以直接从打开的笔记本中执行此操作:

!pip install jupyterthemes
!jt -t chesterish

重新启动主题应用程序的 jupyter 服务器


您不必重新启动jupyter服务器才能使其生效吗?
没错,如果我没记错的话,你需要重新启动内核
不行,需要重启服务器
这在我的情况下不起作用。我没有服务器或任何东西。我在本地 PC 上运行它并将笔记本保存在硬盘上。相同的步骤是否适用于我?在这些命令之后,我们需要做什么?我运行了命令,它们运行了。自定义 css 的文件也在 config 目录下创建,但主题没有变化。
@Meet 如果您在笔记本中运行 !jt ... 命令,请使用 CTRL + SHIFT + RSHIFT + F5 刷新浏览器缓存。 (Chrome 备忘单。检查网页快捷方式support.google.com/chrome/answer/…)。您无需重新启动任何内容即可使主题生效。
r
rafal chlopek

Jupyter 字体大小和内外背景颜色的简单全局更改(此更改将影响所有笔记本)。

在 Windows 中,通过运行以下命令找到配置目录:jupyter --config-dir

在 Linux 中是 ~/.jupyter

在此目录中创建子文件夹 custom 创建文件 custom.css 并粘贴:

/* Change outer background and make the notebook take all available width */
.container {
    width: 99% !important;
    background: #DDC !important;
}   

/* Change inner background (CODE) */
div.input_area {
    background: #F4F4E2 !important;
    font-size: 16px !important;
}

/* Change global font size (CODE) */
.CodeMirror {
    font-size: 16px !important;
}  

/* Prevent the edit cell highlight box from getting clipped;
 * important so that it also works when cell is in edit mode */
div.cell.selected {
    border-left-width: 1px !important;
} 

最后 - 重新启动 Jupyter。结果:

https://i.stack.imgur.com/PyqUg.png


请问,怎么撤销?
删除您创建的文件 (custom.css) 并重新启动 Jupyter。
它有效,但我必须清除我的浏览器缓存。
@rafalchlopek 这是迄今为止最好的解决方案!我尝试了 jupyter 主题和!jt,但它只是想安装,而不是真正“做”任何事情:P,但是谢谢 - 这是一个绝妙的解决方案!
对于那些(像我一样)想要完成粘贴 css 文件的人; (不是我的!)我试过这个,它完美无瑕raw.githubusercontent.com/powerpak/jupyter-dark-theme/master/…
S
Sarthak Singhal

仅适用于暗模式:-

我使用 Raleway 字体进行样式设置

到 C:\User\UserName\.jupyter\custom\custom.css 文件

附加给定的样式,这专门用于 jupyter notebook 的暗模式...

这应该是您当前的 custom.css 文件:-

/* This file contains any manual css for this page that needs to override the global styles.
    This is only required when different pages style the same element differently. This is just
    a hack to deal with our current css styles and no new styling should be added in this file.*/

#ipython-main-app {
    position: relative;
}

#jupyter-main-app {
    position: relative;
}

要追加的内容现在开始

.header-bar {
    display: none;
}

#header-container img {
    display: none;
}

#notebook_name {
    margin-left: 0px !important;
}

#header-container {
    padding-left: 0px !important
}

html,
body {
    overflow: hidden;
    font-family: OpenSans;
}

#header {
    background-color: #212121 !important;
    color: #fff;
    padding-top: 20px;
    padding-bottom: 50px;
}

.navbar-collapse {
    background-color: #212121 !important;
    color: #fff;
    border: none !important
}

#menus {
    border: none !important;
    color: white !important;
}

#menus .dropdown-toggle {
    color: white !important;
}

#filelink {
    color: white !important;
    text-align: centerimportant;
    padding-left: 7px;
    text-decoration: none !important;
}

.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:hover,
.navbar-default .navbar-nav>.open>a:focus {
    background-color: #191919 !important;
    color: #eee !important;
    text-align: left !important;
}

.dropdown-menu,
.dropdown-menu a,
.dropdown-submenu a {
    background-color: #191919;
    color: #fff !important;
}

.dropdown-menu>li>a:hover,
.dropdown-menu>li>a:focus,
.dropdown-submenu>a:after {
    background-color: #212121;
    color: #fff !important;
}

.btn-default {
    color: #fff !important;
    background-color: #212121 !important;
    border: none !important;
}

.dropdown {
    text-align: left !important;
}

.form-control.select-xs {
    background-color: #191919 !important;
    color: #eee !important;
    border: none;
    outline: none;
}

#modal_indicator {
    display: none;
}

#kernel_indicator {
    color: #fff;
}

#notification_trusted,
#notification_notebook {
    background-color: #212121;
    color: #eee !important;
    border: none;
    border-bottom: 1px solid #eee;
}

#logout {
    background-color: #191919;
    color: #eee;
}

#maintoolbar-container {
    padding-top: 0px !important;
}

.notebook_app {
    background-color: #222222;
}

::-webkit-scrollbar {
    display: none;
}

#notebook-container {
    background-color: #212121;
}

div.cell.selected,
div.cell.selected.jupyter-soft-selected {
    border: none !important;
}

.cm-keyword {
    color: orange !important;
}

.input_area {
    background-color: #212121 !important;
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.cm-def {
    color: #5bc0de !important;
}

.cm-variable {
    color: yellow !important;
}

.output_subarea.output_text.output_result pre,
.output_subarea.output_text.output_stream.output_stdout pre {
    color: white !important;
}

.CodeMirror-line {
    color: white !important;
}

.cm-operator {
    color: white !important;
}

.cm-number {
    color: lightblue !important;
}

.inner_cell {
    border: 1px thin #eee;
    border-radius: 50px !important;
}

.CodeMirror-lines {
    border-radius: 20px;
}

.prompt.input_prompt {
    color: #5cb85c !important;
}

.prompt.output_prompt {
    color: lightblue;
}

.cm-string {
    color: #6872ac !important;
}

.cm-builtin {
    color: #f0ad4e !important;
}

.run_this_cell {
    color: lightblue !important;
}

.input_area {
    border-radius: 20px;
}

.output_png {
    background-color: white;
}

.CodeMirror-cursor {
    border-left: 1.4px solid white;
}

.box-flex1.output_subarea.raw_input_container {
    color: white;
}

input.raw_input {
    color: black !important;
}

div.output_area pre {
    color: white
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: white !important;
    font-weight: bolder !important;
}

.CodeMirror-gutter.CodeMirror-linenumber,
.CodeMirror-gutters {
    background-color: #212121 !important;
}


span.filename:hover {
    color: #191919 !important;
    height: auto !important;
}

#site {
    background-color: #191919 !important;
    color: white !important;
}

#tabs li.active a {
    background-color: #212121 !important;
    color: white !important;
}

#tabs li {
    background-color: #191919 !important;
    color: white !important;
    border-top: 1px thin #eee;
}

#notebook_list_header {
    background-color: #212121 !important;
    color: white !important;
}

#running .panel-group .panel {
    background-color: #212121 !important;
    color: white !important;
}

#accordion.panel-heading {
    background-color: #212121 !important;
}

#running .panel-group .panel .panel-heading {
    background-color: #212121;
    color: white
}

.item_name {
    color: white !important;
    cursor: pointer !important;
}

.list_item:hover {
    background-color: #212121 !important;
}

.item_icon.icon-fixed-width {
    color: white !important;
}

#texteditor-backdrop {
    background-color: #191919 !important;
    border-top: 1px solid #eee;
}

.CodeMirror {
    background-color: #212121 !important;
}

#texteditor-backdrop #texteditor-container .CodeMirror-gutter,
#texteditor-backdrop #texteditor-container .CodeMirror-gutters {
    background-color: #212121 !important;
}

.celltoolbar {
    background-color: #212121 !important;
    border: none !important;
}

https://i.stack.imgur.com/ki59k.png

https://i.stack.imgur.com/V3UXJ.png


这个答案在 2020 年已经过时了。
为什么它已经过时了?
M
MasterOne Piece

使用 FireFox 插件“Darker Jupyter”。


谢谢,这对我来说是正确的方法。 'jupyterthemes' 在我的系统上都搞砸了。 (带有默认字体和 Firefox 的 Ubuntu 20.04 LTS)
只要 Firefox 是默认浏览器,它就可以工作。其他浏览器也有这样的插件吗?
W
Wojciech Moszczyński
!pip install jupyterthemes

运行这个库:

from jupyterthemes import get_themes
import jupyterthemes as jt
from jupyterthemes.stylefx import set_nb_theme

和这个:

set_nb_theme('monokai')

主题:

'monokai'、'chesterish'、'oceans16'、'solarizedl'、'solarizedd'、'grade3'、'onedork'


D
Devesh

您可以按照以下步骤操作。

pip install jupyterthemes 或 pip install --upgrade jupyterthemes 升级到最新版本的主题。之后列出您拥有的所有主题:jt -l 之后 jt-t 例如 jt -t solarizedl


o
ontheway

要使用 conda 直接安装 Jupyterthemes 包,请使用:

conda install -c conda-forge jupyterthemes

然后,正如其他人指出的那样,使用 jt -t <theme-name> 更改主题


V
VideoPac

我的完整解决方案:

1) 在 chrome 上获取 Dark Reader,它不仅可以为您提供一个很棒的 Jupyter 黑暗主题,还可以为您想要的每个网站提供(您可以使用不同的过滤器。我使用动态)。

2)将这些代码行粘贴到您的笔记本中,使图例和轴变得可见:

from jupyterthemes import jtplot
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False)

你已经准备好参加迪斯科编码之夜了!


C
Ceyhun
conda install jupyterthemes

在 Windows 中对我不起作用。我正在使用蟒蛇。

但,

pip install jupyterthemes

在 Anaconda Prompt 工作。


您需要为 conda 指定正确的集合:conda install -c conda-forge jupyterthemes
M
Madhav

您可以使用正在运行的笔记本中的 set_nb_theme 更改主题

!pip install jupyterthemes

from jupyterthemes import get_themes
import jupyterthemes as jt
from jupyterthemes.stylefx import set_nb_theme

set_nb_theme('chesterish')

https://www.kaggle.com/getting-started/97540 粘贴


S
Senthil

如果有人有兴趣在启用主题的 docker 中运行 anaconda

docker run -t --rm -p 8888:8888 -v $(pwd):/opt/notebooks continuumio/anaconda3 /bin/bash -c "pip install jupyterthemes; jt -t onedork; /opt/conda/bin/jupyter notebook --ip=0.0.0.0 --port=8888 --notebook-dir=/opt/notebooks --allow-root --no-browser;"

m
maciejwww

如前所述,您可以安装使用更广泛的 jupyterthemes
但是,我也更喜欢并推荐使用更容易且不影响 jupyter-notebook 的默认形状的 jupyter-themer

安装:pip install jupyter-themer

包含文档和示例的存储库(*目前,示例存储在未合并的拉取请求中):@github: jupyter-thamer

我最喜欢的自定义:jupyter-themer -b dark -c zenburn