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

Jupyter Notebook加载JavaScript失败问题求助(涉及JupyterLab)

问题:Python 3.8分子可视化脚本在Jupyter Notebook无法运行(VS Code正常)

我编写了基于Python 3.8.X的分子交互式可视化脚本,在VS Code中运行正常,但经典Jupyter Notebook当前无法正常工作(两周前可正常运行)。因工作需求,该脚本需在Jupyter Notebook中运行,但我在个人Arch Linux机器和工作Ubuntu工作站上均无法正确配置Jupyter环境,即便此前两者均能正常运行。

已收集信息

  • 同一代码单元在Jupyter Notebook与VS Code中的输出截图
  • jupyter nbextension list执行输出
  • jupyter troubleshoot执行输出(对其中sys.<var>路径含义存疑,切换Python 3.8内核后问题依旧)
  • jupyter notebook --debug日志显示404错误:请求/static/components/marked/lib/marked.js失败

已尝试的解决操作

  • 检查所有jupyter --paths下的配置文件,确认jupyter-js-widgets=true
  • 使用Python 3.8和Python 3.10内核
  • 通过不同Python版本升级、强制重装jupyter、notebook、ipywidgets等组件
  • 执行jupyter contrib nbextension install
  • 禁用/启用不同Jupyter nbextensions
  • 安装、启用后又卸载JupyterLab并安装py3dmol扩展

可行的解决方向

1. 修复marked.js静态文件缺失问题

  • 确保Python 3.8环境下安装marked包:
    python3.8 -m pip install marked --force-reinstall
    
  • 定位Jupyter静态文件目录:执行python3.8 -c "import jupyter_core; print(jupyter_core.paths.static_path())"获取路径
  • 检查components/marked/lib/子目录是否存在,若不存在则手动创建
  • 从npm包提取marked.js:全局安装npm包npm install -g marked,找到安装路径(如/usr/lib/node_modules/marked/lib/marked.js),将文件复制到上述Jupyter静态目录的对应位置

2. 彻底重置Jupyter配置

  • 备份现有配置:
    mv ~/.jupyter ~/.jupyter_backup
    
  • 重新生成配置文件:
    python3.8 -m jupyter notebook --generate-config
    
  • 重新安装并启用ipywidgets:
    python3.8 -m pip install ipywidgets widgetsnbextension --force-reinstall
    python3.8 -m jupyter nbextension enable --py widgetsnbextension
    

3. 排查Python环境路径冲突

  • 确认当前使用的Jupyter归属Python 3.8环境:
    which jupyter
    python3.8 -m jupyter --version
    
  • 若路径不一致,激活Python 3.8虚拟环境后,重新安装Jupyter:
    python3.8 -m pip install jupyter notebook --force-reinstall
    

4. 清理第三方nbextensions残留

  • 禁用所有第三方扩展,仅保留核心组件:
    jupyter nbextension disable --all
    jupyter nbextension enable --py widgetsnbextension
    
  • 测试脚本运行,若恢复正常再逐一启用所需扩展排查问题

内容的提问来源于stack exchange,提问作者tsk

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 04:10:27