Jupyter notebook 在命令行上将自定义预处理器与jupyter nbconvert v5.3.1一起使用
我正在尝试执行我在命令行上编写的名为Jupyter notebook 在命令行上将自定义预处理器与jupyter nbconvert v5.3.1一起使用,jupyter-notebook,jupyter,nbconvert,Jupyter Notebook,Jupyter,Nbconvert,我正在尝试执行我在命令行上编写的名为RemoveCellsWithNoTags的自定义预处理器。下面是我尝试的命令 jupyter nbconvert --Exporter.preprocessors=["custompreprocessor.RemoveCellsWithNoTags"] --to script mynotebook.ipynb 这给了我以下的错误 zsh: no matches found: --Exporter.preprocessors=[custompreproces
RemoveCellsWithNoTags
的自定义预处理器。下面是我尝试的命令
jupyter nbconvert --Exporter.preprocessors=["custompreprocessor.RemoveCellsWithNoTags"] --to script mynotebook.ipynb
这给了我以下的错误
zsh: no matches found: --Exporter.preprocessors=[custompreprocessor.RemoveCellsWithNoTags]
标准命令运行良好
jupyter nbconvert --to script mynotebook.ipynb
为了完整起见,这里是我的custompreprocessor.py
文件中的代码
from nbconvert.preprocessors import Preprocessor
class RemoveCellsWithNoTags(Preprocessor):
def preprocess(self, notebook, resources):
notebook.cells = [cell for cell in notebook.cells if 'tags' in cell.metadata]
return notebook, resources
更新#1-使用配置文件的变通方法
我已经设法让它与配置文件一起工作,虽然这对我来说并不理想,但它正在工作
nb\u convert\u config.py
文件内容
c = get_config()
c.NbConvertApp.notebooks = ['mynotebook.ipynb']
c.NbConvertApp.export_format = 'python'
c.Exporter.preprocessors = ['custompreprocessor.RemoveCellsWithNoTags']
然后,命令变为
jupyter nbconvert --config nbconvert_config.py
您可能只需要从shell中退出
[
和]
(zsh):
线索在您收到的错误消息中
zsh: no matches found: --Exporter.preprocessors=[custompreprocessor.RemoveCellsWithNoTags]
错误消息来自shell-而不是jupyter nbconvert 语法如下:
preprocess.py
从nbconvert.preprocessors导入预处理器
类RemoveCellsWithNoTags(预处理器):
def预处理(自我、笔记本、资源):
可执行_单元=[]
对于notebook.cells中的单元格:
如果cell.metadata.get('tags'):
如果在cell.metadata.get('tags')中“跳过”:
持续
可执行单元格。追加(单元格)
notebook.cells=可执行单元
归还笔记本、资源
然后导出笔记本:
jupyter nbconvert --Exporter.preprocessors=[\"preprocess.RemoveCellsWithNoTags\"] getting-started-keras.ipynb
jupyter nbconvert --Exporter.preprocessors=[\"preprocess.RemoveCellsWithNoTags\"] getting-started-keras.ipynb