jupyter / help

:sparkles: Need some help or have some questions? Please visit our Discourse page.
https://discourse.jupyter.org
291 stars 97 forks source link

How to Download from Jupyter Notebook without Extra Comments and Shebang? #472

Open barmanroys opened 5 years ago

barmanroys commented 5 years ago

Apologies if the solution is trivially simple.

Using Jupyter Notebook for Python scripting. When I download a notebook as a .py file (clicking on File->Download as->Python (.py)), Jupyter adds a bunch of extraneous commented lines. It adds some interpreter shebang, encoding declaration at the beginning, and then #In[], #Out[] for each cell etc. To make matters more troublesome, the shebang looks like

#!/usr/bin/env python even though I am using a python3 kernel.

While I am sure it has the best intentions, usually I want to have my own interpreter directive and skip the other commented lines altogether since they do nothing but adding to the clutter.

How to download just the raw codes, only with comments that I inserted, and cells separated by nothing but line breaks?

Also, I would like to know a permanent solution to change the configuration to download it from the menu, for all ipynb files on my machine, not a one time commmand.

Browser: Chrome 70.0.3538.110 (Official Build) (64-bit) Platform: Ubuntu 18.04 and Windows 10 (On separate PCs)

minrk commented 5 years ago

This is handled by nbconvert ScriptExporter. You can use a custom python.tpl that has empty blocks for markdown cells, header, and input prompt, which should get you close to what you want.