Open IPython notebooks (*.ipynb) in read-only view

2020-05-18 05:33发布

问题:

Nowadays with more and more IPython notebook files (*.ipynb) around, it is very disturbing every time when I want to peek at some notebook I have to open a server for it, and cannot do it in read-only mode. Due to auto-save I can accidentally change the file when reading it if not in read-only mode.

I hope something like this: ipython notebook mynb.ipynb --read-only would work, but sadly it doesn't (although still it creates a server which I don't really want in read-only view). What I really want is to open an ipynb file like a HTML file for reading; currently it seems a missing view of ipynb file, and now the notebook is more like a black-box or near-binary file alone.

(P.S. I am using Linux/Ubuntu.)

回答1:

Try this ipynb Viewer. This renders ipython notebook as a static web-page. Also ypu can convert ipyhton notebook to other formats using

ipython nbconvert --to FORMAT notebook.ipynb.

Refer Convert Ipython notebook to other formats. Using this you can convert ipython notebook to HTML.



回答2:

When you change the notebook files' permissions, jupyter's auto-save doesn't touch them:

chmod a-w *.ipynb

Then jupyter goes into read-only mode:



回答3:

You may also want to try nteract app (https://nteract.io)

nteract is a desktop application that allows you to develop rich documents that contain prose, executable code (in almost any language!), and images.

Here you can find more detailed review of the app.

It is completely free and very convenient tool by itself and I use it quite often to see other ipynb files if needed and for quick development.



回答4:

The best I can suggest - unfortunately still a bit verbose - is using nbconvert to create a HTML version of the file, then opening it with your browser. Below are commands to do this (assuming that your browser is set up as the default program to handle .html files). Just replace yournotebook.ipynb with your real Notebook name.

Linux
jupyter nbconvert --to html yournotebook.ipynb --output /tmp/notebook.html &&
xdg-open /tmp/notebook.html
macOS
jupyter nbconvert --to html yournotebook.ipynb --output /tmp/notebook.html &&
open /tmp/notebook.html

Windows
jupyter nbconvert --to html yournotebook.ipynb --output "%TEMP%\notebook.html" && start "" "%TEMP%\notebook.html"

(Note that if you want to do this in bulk, perhaps in a loop in a script, you'll probably want to modify the commands above to not always use the same filename for the HTML file, to avoid the race condition where the HTML file has been overwritten by the time the browser actually gets round to starting to read it.)



回答5:

Intellij IDEA (which is also available as free open-source community edition) can render ipynb files as well. In fact it also allows to author notebooks, so it's not just a viewer.

It can be used via file type associations or via the command line launcher (e.g. idea foo.pynb).



回答6:

I use Github Gist for that. You'll need a Github account.

If you specify *.ipynb file extension there for your content copy/paste, it'll detect it and format as html view. You'll be able even sharing it with someone using link if that's interesting. No tools required other than having a browser.

I've found some glitches in formatting though, mostly with output plots, but it's reasonably rare.

Random example here: https://gist.github.com/Clockware/aa7e01722579841d5888ca83385a5f1d



回答7:

I was able to read .ipynb files as html in visual code. You would need a python plugin for it which visual code auto detects. Fairly straight forward after that.