code-review-graph 工具报 ImportError:如何安装对应的可选依赖组

发布时间:2026/9/14 18:36:22
code-review-graph 工具报 ImportError:如何安装对应的可选依赖组 code-review-graph 工具报 ImportError如何安装对应的可选依赖组【免费下载链接】code-review-graphLocal-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.项目地址: https://gitcode.com/GitHub_Trending/co/code-review-graph用 code-review-graph 时基础功能build、status、图谱查询已经能跑但个别工具一执行就抛出ImportError。原因是包的核心依赖只保证基础功能可用向量嵌入、社区检测、评估、Wiki 摘要等能力被拆成了 pip 可选依赖组optional-dependencies没有安装时对应模块缺失。本文的目标根据报错判断缺的是哪个可选组装上之后验证功能恢复。文档依据来自 docs/TROUBLESHOOTING.md 的 “Optional dependency groups” 章节和 README.md 的 “Optional dependency groups” 小节包定义见 pyproject.toml。从 ImportError 文本定位要装的组多数可选依赖缺失时报错信息里直接带了解决命令。源码中三处ImportError消息可以对照语义搜索/本地嵌入sentence-transformers 缺失sentence-transformers not installed. Run: pip install code-review-graph[embeddings]code_review_graph/embeddings.pyGoogle Gemini 嵌入google-genai 缺失google-genai not installed. Run: pip install code-review-graph[google-embeddings]code_review_graph/embeddings.py评估基准读取 YAML 配置code_review_graph/eval/runner.pypyyaml is required: pip install code-review-graph[eval]也就是说先完整读取报错文本如果消息里带有pip install ...指令按提示安装对应组即可如果报错没有指明用下面这张映射表按你正在使用的功能对号入座。可选组对应的功能安装命令embeddings语义搜索、本地向量嵌入sentence-transformerspip install code-review-graph[embeddings]google-embeddingsGoogle Gemini 嵌入google-genaipip install code-review-graph[google-embeddings]communitiesigraph 社区检测pip install code-review-graph[communities]enrichment基于 Jedi 的 Python 调用解析增强pip install code-review-graph[enrichment]eval评估基准matplotlibpip install code-review-graph[eval]wikiWiki 的 LLM 摘要ollamapip install code-review-graph[wiki]all以上全部可选依赖pip install code-review-graph[all]安装可选依赖组文档给出的安装方式统一是带引号的pip install引号防止 shell 把[...]当成通配符pip install code-review-graph[embeddings]按你缺的能力替换组名即可。需要一次性补齐所有可选能力时pip install code-review-graph[all]注意 pyproject.toml 声明的requires-python 3.10装可选组用的 Python 环境需要满足这个版本并且要和你平时运行code-review-graph的是同一个环境——如果之前pip install装在不在PATH里的目录里可先按 docs/TROUBLESHOOTING.md 中 “code-review-graph: command not found” 一节处理pipx、uvx 或python -m code_review_graph再在同一环境里补装可选组。验证安装是否生效主路径的验证方式就是重新执行之前报ImportError的那条命令或那个工具装对了组这个导入错误不再出现。几个组的补充验证点和已知行为文档中有明确说明embeddings装完后运行embed_graph_tool计算向量文档说明首次嵌入运行会下载模型约 90MB一次性这是正常现象不是报错见 docs/TROUBLESHOOTING.md 的 “Embeddings not working” 一节。communities没装 igraph 时社区检测不会报错而是回退到基于文件的分组文档描述为 “less precise but functional”code_review_graph/communities.py 中 igraph 导入失败即走回退。enrichment没装 jedi 时 Python 调用解析增强被直接跳过只记一条Jedi not installed, skipping Python enrichment日志不抛错code_review_graph/jedi_resolver.py。wiki装了[wiki]组只是具备 ollama 客户端LLM 摘要还需要一个正在运行的 Ollama 实例没有 Ollama 时 Wiki 页面只含结构信息、没有正文摘要docs/TROUBLESHOOTING.md 的 “Wiki generation with LLM summaries” 一节。后两条提醒一点社区检测和 Jedi 增强在依赖缺失时是静默降级而不是ImportError所以“没有报错”不等于可选组已安装。如果你的诉求是“结果精度不如预期”而不是报错也应该按上表核对对应组是否已装。两个容易误判的情况OpenAI 兼容 / MiniMax 嵌入不需要装任何组。文档明确说明它们使用标准库 HTTP 客户端只需设置对应环境变量如CRG_OPENAI_BASE_URL、CRG_OPENAI_API_KEYVoyage 用VOYAGE_API_KEY见 README.md 的 “Environment Variables” 小节。如果你的环境走的是这条路径报ImportError时应重新核对 provider 配置而不是装组。eval 组的历史报错形态。早期版本未装[eval]时eval命令崩在AttributeError: NoneType object has no attribute safe_loadPR #222 修复后统一为上面那条带安装提示的ImportError见 CHANGELOG.md 中 PR #222 条目。如果看到旧形态的AttributeError说明装的是修复前的版本可pip install --upgrade code-review-graph后再按ImportError流程处理。另外SVG 图谱导出单独依赖 matplotlib缺失时报matplotlib is required for SVG export. Install with: pip install matplotlibcode_review_graph/exports.py装[eval]组会带上 matplotlib但直接用pip install matplotlib也可以满足这一项。装完并验证通过后如果该工具是 MCP 侧的工具比如通过 Claude Code 调用无需额外重新注册可选组影响的是包本身的导入重启一下依赖该工具的运行会话即可看到恢复。【免费下载链接】code-review-graphLocal-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.项目地址: https://gitcode.com/GitHub_Trending/co/code-review-graph创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考