简体   繁体   English

从 Jupyter 笔记本运行 Windows 命令行和 arguments

[英]Running a Windows command line with arguments from Jupyter notebook

At the end of my notebook, I want to export an HTML version of it.在我的笔记本末尾,我想导出它的 HTML 版本。 So I use the jupyter nbconvert command line utility in a notebook cell:所以我在笔记本单元格中使用jupyter nbconvert命令行实用程序:

!jupyter nbconvert '$nb_path' --output '$nfname'

where nb_path contains the path to the notebook file ( .ipynb ) and nfname is a name that ends in .html .其中nb_path包含笔记本文件 ( .ipynb ) 的路径, nfname是以.html结尾的名称。

This works fine on a Mac, but fails in Windows 10. There I get as output:这在 Mac 上运行良好,但在 Windows 10 中失败。我得到 output:

"This application is used to convert..."

that is, the same output as if I run just jupyter nbconvert (without arguments) in a cmd prompt.也就是说,相同的 output 就像我在 cmd 提示符中运行jupyter nbconvert (不带参数)一样。

If I open a cmd prompt and manually type the above command (with the actual file names instead of the variable names), then everything executes just fine.如果我打开 cmd 提示符并手动键入上述命令(使用实际文件名而不是变量名),那么一切都执行得很好。

So it seems that the !所以看来! shortcut in jupyter notebook cell doesn't pass the arguments properly to the windows terminal. jupyter 笔记本单元格中的快捷方式无法将 arguments 正确传递到 windows 终端。 Is there a mechanism to do that, or do I have to resort to Popen ?有没有一种机制可以做到这一点,还是我必须求助于Popen

Use double quotes:使用双引号:

!jupyter nbconvert "$nb_path" --output "$nfname"

works for me on Windows 10在 Windows 10 上为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM