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

如何在VS Code中实现类似Google Colab的Jupyter单元格执行完成通知?

在VS Code中实现Jupyter Notebook单元格执行完成通知

方法一:使用VS Code内置设置(最简单)

  • 打开VS Code设置界面:按下Ctrl+,(Windows/Linux)或Cmd+,(Mac)
  • 在搜索框输入notebook cell execution notifications
  • 找到Notebook > Cell: Execution Notifications选项,根据需求选择:
    • onSuccess:仅在单元格执行成功时弹出通知
    • onError:仅在执行出错时弹出通知
    • always:无论成功或失败都弹出通知
  • 可选:调整Notebook > Cell: Execution Notification Duration参数,设置通知显示的时长(单位为毫秒,默认5000毫秒)

方法二:自定义脚本触发系统通知(灵活可控)

如果需要更个性化的通知(比如自定义内容、指定特定单元格触发),可以在Notebook中添加以下脚本:

import os
import platform

def notify_completion(message="单元格执行完成!"):
    if platform.system() == 'Darwin':  # macOS系统
        os.system(f'''osascript -e 'display notification "{message}" with title "Jupyter 执行通知"' ''')
    elif platform.system() == 'Windows':  # Windows系统
        os.system(f'''powershell -Command "Add-Type -AssemblyName System.Windows.Forms; $notify = New-Object System.Windows.Forms.NotifyIcon; $notify.Icon = [System.Drawing.SystemIcons]::Information; $notify.BalloonTipTitle = 'Jupyter 执行通知'; $notify.BalloonTipText = '{message}'; $notify.Visible = $true; $notify.ShowBalloonTip(5000)"''')
    elif platform.system() == 'Linux':  # Linux系统
        os.system(f'''notify-send "Jupyter 执行通知" "{message}"''')

在需要触发通知的单元格末尾调用该函数即可,比如:

# 你的业务代码
df = pd.read_csv("data.csv")
df_processed = df.dropna()

# 触发通知
notify_completion("数据清洗完成!")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 18:44:59