You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改通过pip安装的JupyterLab的代码语法着色?

修改Pip安装版JupyterLab代码语法高亮颜色的方法

方法一:通过JupyterLab设置文件自定义CSS

  1. 定位用户设置目录
    • Linux/macOS:~/.jupyter/lab/user-settings/@jupyterlab/codemirror-extension
    • Windows:C:\Users\<你的用户名>\.jupyter\lab\user-settings\@jupyterlab\codemirror-extension
  2. 编辑settings.jupyterlab-settings文件
    打开文件后,添加自定义CSS规则覆盖关键字颜色。以将import这类关键字改为紫色为例:
    {
      "theme": "JupyterLab Light", // 替换为你正在使用的主题
      "customCSS": ".cm-keyword { color: #9933ff !important; }"
    }
    
    • .cm-keyword是CodeMirror为关键字(包括import)定义的CSS类
    • #9933ff是示例紫色值,可根据需求替换为其他十六进制颜色码
  3. 重启JupyterLab并刷新浏览器页面,设置即可生效

方法二:使用全局自定义CSS文件

  1. 在用户Jupyter目录下创建custom.css文件:
    • Linux/macOS:~/.jupyter/custom/custom.css
    • Windows:C:\Users\<你的用户名>\.jupyter\custom\custom.css
  2. 在文件中添加样式规则:
    .cm-keyword {
      color: #9933ff !important;
    }
    
  3. 重启JupyterLab,刷新页面后就能看到import等关键字变为紫色

内容的提问来源于stack exchange,提问作者Berg A.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 23:32:38