env-management
它能做什么
这项技能教智能体如何处理笔记本会话中缺失的软件包。它说明如何检查软件包版本,并通过认可的工具安装,而不是在单元格中直接安装。
适用场景
- ✓当笔记本运行因 Python 或 R 缺少软件包而报错时。
- ✓当用户询问笔记本环境中安装了哪个版本的软件包时。
- ✓当代码依赖特定版本的功能,需要检查软件包版本时。
技能链接
https://github.com/aipoch/open-science/blob/main/resources/skills/env-management/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的笔记本报了 pandas 的 ModuleNotFoundError。请修复环境并重新运行。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出缺失的软件包,并使用软件包管理工具在绑定的运行时中安装,而不是修改代码改用其他库。它可以先用检查工具查看已安装的版本。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Environment and package management
The notebook runs against the session's bound runtime: the app-managed default (default-python / default-r) unless you bind another one with notebook_bind_runtime — a named environment you created, or one of the user's own detected interpreters. You never activate environments by hand, and you never install packages from inside a cell. Installs happen in the trusted main process through a single tool, manage_packages, and always land in the currently bound runtime. This page is the workflow for getting a package installed and for knowing when a package is not something you can install yourself.
When a package is missing
A run that fails with ImportError / ModuleNotFoundError (Python) or Error in library(x): there is no package called 'x' (R) means the package is not in the environment yet. The fix is one manage_packages call, not a code change. Do not rewrite the cell to use a different library that "does roughly the same thing" — install the package the task actually needs. Do not fall back to reading data or computing results a worse way to dodge the missing import.
Check an installed version
Use inspect_packages(language, packages) when the user asks whether a package is installed in an app-managed runtime or which version is present, or when your code depends on a version-specific feature. It reads package metadata from the session's bound app-managed runtime without importing the package or changing the environment. An installed result does not prove the import will succeed; use notebook_execute when importability itself is the question.
Inspection does not provision a missing app-managed default runtime. If it reports DEFAULT_RUNTIME_NOT_READY, use notebook_execute in that language to prepare the runtime under notebook execution approval, then retry inspect_packages.
inspect_packages intentionally rejects a user-owned external runtime because reading its metadata executes that interpreter. Use notebook_execute for an external runtime so the user sees the normal notebook execution approval.
Do not use inspection as a mandatory preflight for every install. For a clear missing-package error, call manage_packages directly; installation is the recovery action, while inspection is for explicit version and compatibility questions.
Route by language
- Python package →
manage_packages(language="python", packages=["numpy", "pandas"]). - R package →
manage_packages(language="r", packages=["ggplot2"]). R packages install from conda-forge asr-<name>automatically; pass the plain CRAN name (ggplot2, notr-ggplot2). - A PyPI-only Python package that is not on conda → add
usePip=true. - A package that needs a specific conda channel → pass
channels=["bioconda"]. Leavechannelsoff otherwise; the app supplies the right default mirror.
manage_packages always returns a target receipt. When resolution succeeds, it identifies the implicit default or explicit binding and the actual runtime; selection:"unresolved" means no target could be established. After a failed bind or switch, inspect bindingChanged and target before deciding where a later install would run. Every install persists — there is no "temporary" install to undo later. Install once; it stays available in later cells and sessions on that runtime. To install into a different environment, bind or switch to it first (notebook_bind_runtime / notebook_switch_runtime); there is no per-call environment argument. The app-managed defaults are additive-only (bare name or name==version); for uninstalls, version ranges, or git/URL specs, create a named environment and install there.
Restart the kernel after an install when told to
manage_packages returns a compact result with ok, needsRestart, the installer method, the target receipt, verified packageChanges, and an actionable error on failure. A requested package change reports installed, updated, unchanged, or removed plus its observed before/after version when available. unchanged means only that distribution metadata in the reported target did not change; it does not prove the current Kernel can import the module. When importability or the loaded version matters, use notebook_execute to import the package and inspect its version. When needsRestart is true (always true for R, because the running kernel holds the old library state), call notebook_restart before you `import
常见问题
我可以在单元格中运行 pip install 吗?
不可以。技能说明,不允许在单元格中安装,安装需通过软件包管理工具进行。
我应该改用其他库的代码吗?
不应该。技能说明,应安装任务实际需要的软件包。
软件包会安装到哪个环境?
安装到与会话绑定的环境中,可以是应用默认环境,也可以是指定的命名环境。
详情
作者的原始描述
Use when a notebook run fails on a missing package (ImportError, ModuleNotFoundError, "there is no package called"), when you need to inspect an installed package version, or when you need to install, add, or manage Python or R packages for the notebook runtime. Covers inspect_packages, routing Python vs R through manage_packages, why in-cell %pip/!pip/install.packages() and OS installers are forbidden, restarting the kernel after an install, and when to stop and ask the user.
repo: aipoch/open-science
热度
- GitHub 星标
- 5.4k
- 排名
- #14857
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
alphafold2
5.4k帮你的智能体通过 ColabFold 运行器,使用 AlphaFold2 根据蛋白质序列预测其三维结构,包括蛋白质复合物。
boltz
5.4k帮你的智能体使用开源的 Boltz-2 模型预测蛋白质、DNA、RNA 和小分子复合物的结构,并可选择估算结合亲和力。
borzoi
5.4k帮你的智能体根据 DNA 序列预测全基因组的活性轨迹,例如表达和可及性,并通过预测效果比较变异。
chai1
5.4k帮你的智能体通过一个 FASTA 文件,使用 Apache 许可的 Chai-1 模型预测蛋白质、核酸和配体复合物的结构。