关于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,解决!!!!

相关推荐
basketball61612 分钟前
Python torchvision.transforms 下常用图像处理方法
开发语言·图像处理·python
兔子蟹子16 分钟前
Java集合框架解析
java·windows·python
宁酱醇20 分钟前
各种各样的bug合集
开发语言·笔记·python·gitlab·bug
谷晓光28 分钟前
Python 中 `r` 前缀:字符串处理的“防转义利器”
开发语言·python
姚毛毛29 分钟前
Windows上,10分钟构建一个本地知识库
python·ai·rag
站大爷IP1 小时前
Python ZIP文件操作全解析:从基础压缩到高级技巧
python
纪元A梦1 小时前
华为OD机试真题——通过软盘拷贝文件(2025A卷:200分)Java/python/JavaScript/C++/C语言/GO六种最佳实现
java·javascript·c++·python·华为od·go·华为od机试题
用户867132495741 小时前
97% 的 Python 项目可以使用 partial() 更简洁
python
灏瀚星空2 小时前
从单机工具到协同平台:开源交互式模拟环境的技术演进之路
经验分享·笔记·python·开源·oneapi
西柚小萌新2 小时前
【Python爬虫实战篇】--Selenium爬取Mysteel数据
开发语言·爬虫·python