jupyter_notebook更换配色

jupyter-themes: 修改 jupyter notebook 的主题

安装方法

  • 安装

    看jupyter是用conda还是pip装的

    conda list | grep -e '^jupyter '
    jupyter                   1.0.0            py36h9896ce5_0    【defaults】
    • 【】中为default,则是jupyter notebook是conda安装的,强烈建议用conda安装jupyterthemes,不然若用pip安装jupyterthemes,会出现多种依赖不匹配

      conda install -c conda-forge jupyterthemes
    • 【】中为pypi,jupyter notebook是pip安装的,则

      pip install jupyterthemes
  • 配置

    终端下输入以下命令

    jt -t gruvboxd -T -N -cellw 90% -f roboto -fs 11

    这表示我选择了 gruvboxd 这个主题,同时希望打开顶部的工具栏(Toolbar),显示笔记本的名字(Name),文本框占浏览器页宽的90%,用roboto等宽字体,字号11

    运行过程中可能会返回报错如下,这说明已经别的用户安装了jupyterthemes,并重建了/tmp/yacctab.py,故你无法重写这个文件,这并不运行你使用jupyter notebook的配色。你的配色设置,保存到 $HOME/.jupyter/custom/,不和他的配色设置冲突。

    WARNING: Couldn’t create ‘yacctab’. [Errno 13] Permission denied: ‘/tmp/yacctab.py’
    WARNING: Couldn’t create ‘yacctab’. [Errno 13] Permission denied: ‘/tmp/yacctab.py’

  • 配置文件

    配置文件保存到了 $HOME/.jupyter/custom/,下是四个配置和依赖文件current_theme. txt, custom.css, custom.js, fonts/,之后每次执行jupyter notebook启动notebook时,会加载此配置,看见你要的主题。

依赖不匹配怎么解决

若jupyter notebook是conda安装,却用安装pip安装jupyterthemes,会出现多种依赖不匹配,最终如下装一圈依赖,才能安装成功

conda upgrade notebook libsodium
pip install jupyterthemes
pip install --upgrade --user nbconvert
pip install --upgrade ipykernel

以下是各个依赖不匹配的详解:

Found existing installation: terminado 0.6

执行pip install jupyterthemes时报错

notebook 5.7.6 has requirement jupyter-core>=4.4.0, but you’ll have jupyter-core 4.3.0 which is incompatible.

Installing collected packages: lesscpy, terminado, pyzmq, jupyter-client, prometheus-client, Send2Trash, notebook, jupyterthemes
Found existing installation: terminado 0.6
Cannot uninstall ‘terminado’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

这是因为,上述操作中pip自动更新了notebook,但这个notebook是用conda而非pip装的,故依赖项terminado不对

解决方法:

conda upgrade notebook

而后可正常安装

pip install jupyterthemes

ImportError: libsodium.so.23

执行jupyter notebook,报错

ImportError: libsodium.so.23: cannot open shared object file: No such file or directory

这是由于jupyterthemes依赖的libsodium没有更新

解决办法:

conda update libsodium
# 或
conda install -c conda-forge libsodium

ModuleNotFoundError: No module named ‘nbconvert.exporters.base’

运行notebook时,用浏览器成功打开notebook的目录网页,但无法打开/新建python3 的 notebook文件,命令行下报错

ModuleNotFoundError: No module named ‘nbconvert.exporters.base’

[E 20:28:58.544 NotebookApp]

这是因为,这是由于jupyterthemes依赖的nbconvert没有更新

解决办法:

pip install --upgrade --user nbconvert

然后将$USER/.local/bin添加到PATH,即可实现上述运行

ERROR:tornado.general: Uncaught exception in zmqstream callback

运行notebook时,用浏览器成功打开notebook的目录网页,能成功打开/新建python3 的 notebook文件,但点运行,迟迟不运行,命令行下报错

ERROR:tornado.general: Uncaught exception in zmqstream callback

这是因为,这是由于jupyterthemes依赖的ipykernel没有更新

解决办法:

pip install --upgrade ipykernel

参考

https://github.com/dunovank/jupyter-themes

【内容引起舒适】让你的Jupyter Notebook不再辣眼睛