Jupyter Notebook主题字体设置及自动代码补全

Posted qiuxirufeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jupyter Notebook主题字体设置及自动代码补全相关的知识,希望对你有一定的参考价值。

Jupyter Notebook用久了就离不开了,然而自带的主题真的不忍直视。为了视力着想,为了自己看起来舒服,于是折腾了一番。。在github上发现了一个jupyter-themes工具,可以通过pip安装,非常方便使用。

首先是主题下载,命令行如下所示:

pip install --no-dependencies jupyterthemes==0.18.2

安装好了,有的电脑可能会提示缺少 lesscpy,继续 pip 安装

pip install lesscpy

然后是对主题选择、字体大小进行设置,我总结了一个我最喜欢的

jt --lineh 140 -f consolamono -tf ptmono -t grade3 -ofs 14 -nfs 14 -tfs 14 -fs 14 -T -N

 命令行的格式的解释如下表所示

cl options arg default
Usage help -h --
List Themes -l --
Theme Name to Install -t --
Code Font -f --
Code Font-Size -fs 11
Notebook Font -nf --
Notebook Font Size -nfs 13
Text/MD Cell Font -tf --
Text/MD Cell Fontsize -tfs 13
Pandas DF Fontsize dfs 9
Output Area Fontsize -ofs 8.5
Mathjax Fontsize (%) -mathfs 100
Intro Page Margins -m auto
Cell Width -cellw 980
Line Height -lineh 170
Cursor Width -cursw 2
Cursor Color -cursc --
Alt Prompt Layout -altp --
Alt Markdown BG Color -altmd --
Alt Output BG Color -altout --
Style Vim NBExt* -vim --
Toolbar Visible -T --
Name & Logo Visible -N --
Reset Default Theme -r --
Force Default Fonts -dfonts --

 

附上最终效果

技术分享图片

 

 接着让 jupyter notebook 实现自动代码补全,首先安装 nbextensions

pip install jupyter_contrib_nbextensions

接着对其进行设置

jupyter contrib nbextension install --user

然后安装 nbextensions_configurator,同样对其进行设置

pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user

如果提示缺少依赖,就使用pip安装对应依赖即可。

最后重启jupyter,在弹出的主页面里,能看到增加了一个Nbextensions标签页,在这个页面里,勾选Hinterland即启用了代码自动补全,如图所示:

技术分享图片

这时打开一个笔记,来感受一下吧。

以上是关于Jupyter Notebook主题字体设置及自动代码补全的主要内容,如果未能解决你的问题,请参考以下文章

Jupyter Notebook 更换主题(背景字体)

随笔-- Jupyter Notebook如何切换主题更改字体大小

随笔-- Jupyter Notebook如何切换主题更改字体大小

设置jupyter notebook字体

用 conda 安装 jupyter-themes: 修改 jupyter notebook 的主题

如何自定义jupyter notebook的主题