直接用jupyterthemes设置主题,避免手动改css或配置目录;若pip安装超时,换清华源(-i https://pypi.tuna.tsinghua.edu.cn/simple/)或豆瓣源;装完需升级并清空~/.jupyter/custom后重设主题,再重启jupyter。

直接用 jupyterthemes 设置,别折腾 CSS 文件或手动改配置目录——它会覆盖、失效、重启后丢失。
安装 jupyterthemes 时 pip 源失败怎么办
国内网络环境下,pip install jupyterthemes 经常超时或 404。这不是你环境问题,是 PyPI 官方源不稳定。
- 换清华源:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jupyterthemes - 或者豆瓣源:
pip install -i https://pypi.doubanio.com/simple/ jupyterthemes - 装完务必升级:
pip install --upgrade jupyterthemes,否则jt -l可能报错或不显示新主题
设置 monokai 黑色主题但图表文字看不见
用了 jt -t monokai 后,Matplotlib 图表的坐标轴标签、刻度线变成黑色,和背景融为一体——不是主题没生效,是 Matplotlib 默认配色没适配暗色背景。
- 临时修复:在绘图代码前加
plt.rcParams['text.color'] = 'white'和plt.rcParams['axes.labelcolor'] = 'white' - 一劳永逸:在 notebook 开头运行
%matplotlib inline后,立即执行plt.style.use('dark_background') - 注意:
plt.tick_params(color='w', labelcolor='w')只管刻度,不管标题和图例,得配合rcParams才完整
重启 Jupyter 后主题失效或变回白色
常见原因是配置未写入用户级配置目录,或旧缓存干扰。不是重装就能解决。
- 先清空旧配置:
rm -rf ~/.jupyter/custom(macOS/Linux)或del /q %USERPROFILE%\.jupyter\custom(Windows CMD) - 再执行主题命令,例如:
jt -t monokai -f fira -fs 12 -cellw 80% -T -N - 必须关闭所有 Jupyter 进程(包括后台的
jupyter-notebook或jupyter lab),再重新运行jupyter notebook - 如果用的是 conda 环境,确保在目标环境中执行
jt命令,否则主题只生效于 base 环境
真正麻烦的不是设置主题,而是主题和绘图库、插件、自定义 CSS 之间的冲突。比如开了 Hinterland 补全插件后,再用 jupyterthemes 覆盖样式,偶尔会导致补全框位置偏移或透明度异常——这种问题没有通用解法,只能关掉一个看哪个优先级更高。











