简体   繁体   中英

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. So I use the jupyter nbconvert command line utility in a notebook cell:

!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 .

This works fine on a Mac, but fails in Windows 10. There I get as 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.

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.

So it seems that the ! shortcut in jupyter notebook cell doesn't pass the arguments properly to the windows terminal. Is there a mechanism to do that, or do I have to resort to Popen ?

Use double quotes:

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

works for me on Windows 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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