关于jinja2高版本api变化导致notebook导出html失败的问题

最新jinja2版本已经到了3.1.2,但是nbconvert引用的应该是老版本,具体代码报错如下

python 复制代码
Type "help", "copyright", "credits" or "license" for more information.
>>> import nbconvert
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\gw00305123\Anaconda3\lib\site-packages\nbconvert\__init__.py", line 4, in <module>
    from .exporters import *
  File "C:\Users\gw00305123\Anaconda3\lib\site-packages\nbconvert\exporters\__init__.py", line 3, in <module>
    from .html import HTMLExporter
  File "C:\Users\gw00305123\Anaconda3\lib\site-packages\nbconvert\exporters\html.py", line 14, in <module>
    from jinja2 import contextfilter
ImportError: cannot import name 'contextfilter' from 'jinja2' (C:\Users\gw00305123\Anaconda3\lib\site-packages\jinja2\__init__.py)

nubconvert会从jinja2导入一个叫contextfilter的东西,但是新版本已经没有了,这会导致我导出一个notebook到html时报错,具体报错信息如下

python 复制代码
10:58:59.463 [error] Export failed [Error: 未安装 Jupyter 松影
	at f_.getExportInterpreter (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:319696)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
	at async v_.executeCommand (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:320876)
	at async E_.export (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:325143)
	at async M_.exportToFormat (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:330191)
	at async M_.performNbConvertExport (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:329960)
	at async M_.performExport (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:329635)
	at async M_.exportImpl (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:329263)
	at async M_.export (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:329019)
	at async $C.export (~\.vscode\extensions\ms-toolsai.jupyter-2023.10.1100000000-win32-x64\out\extension.node.js:24:470042)
	at async d.h (~\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:141:140086)]

从报错信息中并不能看出什么问题,但是从报错信息的上一行,有个导入nbconvert的语句,于是推测跟nbconvert有关,于是有了开头的测试语句,发现是jinja2的版本问题,于是降了一个版本,装了3.0.3,解决!!!!

相关推荐
nbsaas-boot2 小时前
Java 正则表达式白皮书:语法详解、工程实践与常用表达式库
开发语言·python·mysql
仗剑_走天涯2 小时前
基于pytorch.nn模块实现线性模型
人工智能·pytorch·python·深度学习
chao_7892 小时前
二分查找篇——搜索旋转排序数组【LeetCode】两次二分查找
开发语言·数据结构·python·算法·leetcode
chao_7897 小时前
二分查找篇——搜索旋转排序数组【LeetCode】一次二分查找
数据结构·python·算法·leetcode·二分查找
烛阴7 小时前
Python装饰器解除:如何让被装饰的函数重获自由?
前端·python
noravinsc7 小时前
django 一个表中包括id和parentid,如何通过parentid找到全部父爷id
python·django·sqlite
ajassi20007 小时前
开源 python 应用 开发(三)python语法介绍
linux·python·开源·自动化
沉默媛8 小时前
如何安装python以及jupyter notebook
开发语言·python·jupyter
Deng9452013149 小时前
基于Python的旅游数据可视化应用
python·numpy·pandas·旅游·数据可视化技术
2401_878624799 小时前
pytorch 自动微分
人工智能·pytorch·python·机器学习