为 jupyterlab 添加 debugger 扩展

524 阅读1分钟

「这是我参与2022首次更文挑战的第24天,活动详情查看:2022首次更文挑战」。


title: 为 jupyterlab 添加 debugger 扩展 mathjax: false date: 2021-07-08 18:06:53 tags: [Coding, Python] categories: [Coding, Python]

jupyterlab 作为 jupyter 的扩展版本,易用性强,结果保存很合理。突然发现可以添加debugger插件,实现在jupyterlab中调试代码,本文记录方法。

基本流程

  • 安装 Anaconda
  • 安装 jupyterlab
  • 安装 node.js
  • 安装 xpython
  • 建立 jupyterlab 工程
  • 搜索并安装插件
  • 使用插件进行debug

具体步骤

安装Anaconda

安装jupyterlab

pip install jupyterlab

安装 node.js

如果不装会报错:

An error occurred installing <code>@jupyterlab/debugger-extension</code>.
Error message:

Please install Node.js and npm before continuing installation. You may be able to install Node.js from your package manager, from conda, or directly from the Node.js website (https://nodejs.org).
  • 下载地址:nodejs.org/en/download…
  • Win 下载 Windows Installer (.msi)
    • 直接安装即可
  • Linux 下载 Linux Binaries (x64)
wget https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.xz    // 下载
tar xf node-v14.17.3-linux-x64.tar.xz                                   // 解压

之后添加环境变量到 /etc/profile~/.bashrc 文件

export PATH=$PATH:/path_to/node-v14.17.3-linux-x64/bin
  • 测试
# node -v
v14.17.3

安装 xpython

pip install xeus-python

JupyterLab 2.0+

xeus-python 0.8.0+

notebook 6+

  • 随后可以使用 xpython

建立 jupyterlab 工程

jupyter lab --allow-root --no-browser --ip 0.0.0.0 --port 8080 --notebook-dir /workspace/nfs

搜索并安装插件

  • 进入 jupyterlab, enable Warning 中的内容即可使用扩展

  • 搜索并安装插件

安装 @jupyterlab/debugger

  • 可以搜索之间单击 install
  • 也可以执行命令
jupyter labextension install @jupyterlab/debugger

使用插件进行debug

  • 建立 xpython 工程
  • 设置断点,debug 程序

参考资料