Table of Contents


How to list all installed Jupyter kernels?

jupyter kernelspec list

– via StackOverflow

Create a new Jupyter kernel for a Conda env

conda activate <your_conda_env>
pip install --user ipykernel
python -m ipykernel install --user --name=<your_conda_env_but_can_be_something_else_too>

Use Jupyter notebooks for presentations

Install RISE and mark the cells you want to use as slides.

Customize RISE via CSS

In order to change how RISE slides look, create a rise.css file in the same folder and customize it to your liking. See the sample below.

/* set the font size/margins for all headings */
.reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6  {
    font-family: Avenir Next Medium !important;
    font-size: 1.1em !important;
    text-align: center;
    margin-top: 170px !important;
}

/* you know what, just set this everywhere */
.slides .rendered_html {
    font-family: Avenir Next Condensed
}

/* increase font size for code blocks */
.CodeMirror {
    font-size: 1em !important;
} 

/* increase font size for tables i.e. pandas */
table.dataframe {
    font-size: 1em;
}

/* make the images larger, too */
.output_png {
    zoom: 1.5;
}

– via Customizing RISE

Displaying code with syntax highlighting

Old version, works everywhere including Jupyter Notebooks, Jupyter Lab, and Azure Notebooks

def view_source(src, lexer):
    from pygments import highlight
    from pygments.formatters import HtmlFormatter
    from IPython.core.display import HTML

    formatter = HtmlFormatter()
    
    display(HTML(f'<style>{ formatter.get_style_defs(".highlight") }</style>'))
    display(HTML(highlight(src, lexer, formatter)))

# usage
from pygments.lexers import PythonLexer
view_source('print("Hello World")', PythonLexer())

New version, works well only in Jupyter Notebooks

from IPython.display import Code
Code('print("Hello World")', language='python')

In order to have this run in Jupyter Lab too, you’ll need to run the following code beforehand. Follow this GitHub issue for updates.

from pygments.formatters import HtmlFormatter
from IPython.core.display import HTML

formatter = HtmlFormatter()

display(HTML(f'<style>{ formatter.get_style_defs(".highlight") }</style>'))