Quarto编译含diagram filter文档失败,提示找不到nbformat和nbclient
问题描述
尝试编译使用diagram过滤器的Quarto文档(示例代码如下):
--- title: Test author: - John Due filters: - diagram format: beamer: default --- ## Test ```tikz \begin{tikzpicture} \node (i) at (0, 0) {i}; \end{tikzpicture}
编译失败,首先出现Jupyter相关错误:`ModuleNotFoundError: No module named 'nbformat'`。尽管已通过pipx在虚拟环境安装了nbformat(5.10.4)和nbclient(0.10.2),但`quarto capabilities`显示这两个包未被检测到,后续还出现Lua过滤器执行错误。 ### 相关命令输出 1. `quarto check jupyter`输出: ```bash quarto check jupyter Quarto 1.7.31 [✓] Checking Python 3 installation....OK Version: 3.12.3 Path: /usr/bin/python3 Jupyter: 5.3.2 Kernels: python3 (/) Checking Jupyter engine render....Traceback (most recent call last): File "/opt/quarto/share/jupyter/jupyter.py", line 21, in <module> from notebook import notebook_execute, RestartKernel File "/opt/quarto/share/jupyter/notebook.py", line 19, in <module> import nbformat ModuleNotFoundError: No module named 'nbformat' [✓] Checking Jupyter engine render....OK
pipx list输出:
pipx list venvs are in /home/John-Due/.local/share/pipx/venvs apps are exposed on your $PATH at /home/John-Due/.local/bin manual pages are exposed at /home/John-Due/.local/share/man package nbclient 0.10.2, installed using Python 3.12.3 - jupyter-execute package nbformat 5.10.4, installed using Python 3.12.3 - jupyter-trust package radian 0.6.15, installed using Python 3.12.3 - radian
quarto capabilities输出显示nbformat和nbclient为null,且存在Lua过滤器执行错误。
解决步骤
- 核心原因:Quarto当前使用的是系统Python(
/usr/bin/python3),但通过pipx安装的nbformat、nbclient位于隔离的虚拟环境中,系统Python无法访问这些包。 - 安装依赖到正确环境:
直接使用Quarto检测到的Python环境安装所需包:# 全局安装(需sudo权限) sudo /usr/bin/python3 -m pip install nbformat nbclient # 或用户级安装(无需sudo) /usr/bin/python3 -m pip install --user nbformat nbclient - 验证修复:重新运行
quarto check jupyter,确认不再出现ModuleNotFoundError,此时quarto capabilities应该能正常检测到nbformat和nbclient。 - Lua过滤器错误处理:Lua报错通常是Jupyter依赖缺失导致的连锁问题,解决Python依赖后一般会自动恢复。若仍有问题,检查TeX发行版是否已安装tikz相关包(比如TeX Live中的
tikz包)。
内容的提问来源于stack exchange,提问作者mistral
相关产品推荐
相关产品推荐

