执行笔记本

jsboige2026-10-25查看 602复制 796

使用本地脚本或 MCP Jupyter 执行 Jupyter notebook。参数:<notebook_path> [--mode] [--cells] [--timeout] [--batch] [--save]

Download (.md)

📘如何使用这个技能

  1. 1
    复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
  2. 2
    打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
  3. 3
    粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
  4. 4
    直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景

💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。

SKILL.md2092 chars
---
name: execute-notebook
description: Execute Jupyter notebooks using local scripts or MCP Jupyter. Arguments: <notebook_path> [--mode] [--cells] [--timeout] [--batch] [--save]
---

# Execute Notebook

Execute a Jupyter notebook with full lifecycle management.

**Notebook**: `$ARGUMENTS`

## Options

- `--mode`: full (default), selective, papermill
- `--cells`: Specific cells (e.g., 0,5,10)
- `--timeout`: Per-cell timeout in seconds (default 300)
- `--stop-on-error`: Halt on first error
- `--batch`: Enable BATCH_MODE for interactive notebooks
- `--save`: Save outputs to original notebook

## Execution by Kernel Type

### Python (kernel: python3)

**Local scripts (preferred for batch)**:
```bash
# Full execution via notebook_tools.py
python scripts/notebook_tools/notebook_tools.py execute {path} --timeout 300

# Cell-by-cell with verbose output via notebook_helpers.py
python scripts/notebook_tools/notebook_helpers.py execute {path} --verbose

# Specific cell execution
python scripts/notebook_tools/notebook_helpers.py execute {path} --cell 5 --timeout 60
```

**MCP (for interactive debugging)**:
- `manage_kernel(action="start", kernel_name="python3")` + `execute_on_kernel`

### .NET (kernel: .net-csharp)
- **MCP cell-by-cell ONLY** - Papermill and local scripts do NOT work with .NET kernels
- CRITICAL: Set working directory first with `SetCurrentDirectory()`
- See `mcp-jupyter` skill for detailed .NET patterns

### GenAI notebooks
- Check `.env` configuration first (use `/validate-genai`)
- Use `--batch` for notebooks with interactive widgets
- Use dedicated scripts: `python scripts/genai-stack/validate_notebooks.py`

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| Kernel timeout | .NET cold start | Retry (30-60s normal) |
| File not found | Wrong directory | SetCurrentDirectory() |
| ModuleNotFoundError | Missing dependency | pip install |
| API key missing | .env not configured | Check OPENAI_API_KEY etc. |

## Report Format

Report: notebook name, kernel, mode, total/executed/successful/error cells, timing, error details.
来源:skillsdirectory

评论0

登录后参与评论

还没有评论,来抢沙发吧