Skip to content

Jupyter notebooks

Marinna Martini edited this page May 4, 2020 · 5 revisions

More Jupyter tricks

Specify the browser to use:

  1. First find the jupyter config directory with jupyter --config-dir
  2. Then edit this setting in jupyter_notebook_config.py as follows c.NotebookApp.browser = u'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' and note that the direction of the slash and the u at the beginning are important.
    (thanks to https://stackoverflow.com/questions/55554351/no-web-browser-found-could-not-locate-runnable-browser-jupyter-notebook)

Specify the directory to be in (or the top-level): jupyter-notebook --notebook-dir 'the_path' or set this line c.NotebookApp.notebook_dir = 'C:\\Users\\Username' in jupyter_notebook_config.py as you see fit. This is especially helpful in windows when you have data on a different drive.

Some helpful magics to remember:

Insure tab completion

From https://stackoverflow.com/questions/33665039/tab-completion-does-not-work-in-jupyter-notebook-but-fine-in-ipython-terminal?r=SearchResults

%config IPCompleter.greedy=True 

sharing jupyter notebooks using gists

This looks simple in concept, and in practice is a little complicated (as with all things python). If you have a github account, your gists are here: https://gist.github.com/

from jypter notebook

You can gist-it, which is sort of built in, and you have to activate it.

from the command line

This has been necessary for me when I am working from jupyter-lab or if a gist won't load to github, likely if it has holoviews plots, or images that are really large.

  • install python-gist command line gist tool (conda or pip will work), docs are here: https://pypi.org/project/python-gist/
  • set up the config file. On windows, that means a file called .gist in the top level of your user directory, e.g. c:\Users\yourusername\ and put in it what they want you to put in it, your token and a path to an editor (if you don't have it, install Notepad++, it's great).
  • learn how to get a github personal access token: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
  • If you have done this correctly, from an anaconda prompt (in windows), you can type gist list an see a list of your gists. To put one on github, you say gist create "name-of-gist" --public name-of-notebook. It will give you the gist URL.
  • if your gist isn't rendering properly on github, go here: https://nbviewer.jupyter.org/ and drop the gist URL in there. The resulting page is a properly rendered URL you can share around.