Jupyter lab
%debug
u - up
d - down
%%timeit -n3
%load_ext autoreload
%autoreload 2
Display image
from IPython.display import Image
Image(filename=f)
https://jupyterlab.readthedocs.io/en/stable/
https://jupyter-notebook.readthedocs.io/en/stable/config.html#config-file-and-command-line-options
Keyboard shortcuts
https://blog.ja-ke.tech/assets/jupyterlab-shortcuts/Shortcuts.png
Ctrl + b - Hide file tab
Cmd + / - comment code
Ctrl + Shift + [ - move to left tab
Ctrl + Shift + ] - move to right tab
Cmd + ] - indent
Cmd + [ - unindent
Esc -> z - Undo cell operations
Esc + a -> Insert cell above
Esc + b -> Insert cell below
Esc + x -> cut cell
control + shift + - -> Split cell
np.exp? # to see documentation for np.exp
User settings
Settings -> Advanced Settings Editor -> Keyboard Shortcuts; on right pane add:
{
"shortcuts": [
{
"command": "runmenu:restart-and-run-all",
"keys": [
"Ctrl Shift R"
],
"selector": "[data-jp-code-runner]"
},
{
"command": "kernelmenu:restart-and-clear",
"keys": [
"Ctrl Shift C"
],
"selector": "[data-jp-kernel-user]"
}
]
}
Launch with RTC
jupyter lab --collaborative
Config
$ jupyter --paths
$ jupyter notebook --generate-config
$ jupyterhub --generate-config
Open Jupyter notebook in chrome instead of internet explorer
$ jupyter notebook --generate-config
# Open C:\Users\XXXXXX\Documents\Jupyter_Notebooks\.jupyter\jupyter_notebook_config.py
# Change the line #c.NotebookApp.browser = '' to
c.NotebookApp.browser = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
Extensions
jupyter labextension list
jupyter serverextension list
jupyter nbextension list
Execute time
https://github.com/deshaw/jupyterlab-execute-time
$ jupyter labextention install jupyterlab-execute-time
Settings -> Advanced Settings Editor -> Notebook: {"recordTiming": true} in User Preferences
Jupyterlab code formatter
Settings -> Advanced Settings Editor -> Jupyterlab Code Formatter {"formatOnSave": true}
jupyter labextension install dask-labextension
jupyter serverextension enable dask_labextension
jupyter labextension install @bokeh/jupyter_bokeh
jupyter labextension install @pyviz/jupyterlab_pyviz
jupyter labextension install @ryantam626/jupyterlab_code_formatter
jupyter serverextension enable --py jupyterlab_code_formatter
jupyter labextension install @jupyterlab/toc
jupyter labextension install jupyterlab_execute_time
# Settings->Advanced Settings Editor->Notebook: {"recordTiming": true}
jupyter labextension install jupyterlab-topbar-extension
jupyter labextension install jupyterlab-system-monitor
jupyter labextension install jupyterlab-topbar-text
jupyter labextension install jupyterlab-logout
jupyter labextension install jupyterlab-theme-toggle
# npm config get unicode
# npm set unicode false
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install jupyterlab-plotly@4.12.0
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.12.0
# Settings -> Advanced Settings Editor -> Execture time toc: {"collapsibleNotebooks": true} in User Preferences
#
/Users/ray/miniconda3/envs/test_env/share/jupyter/lab/settings/overrides.json:
{
"@jupyterlab/notebook-extension:tracker": {
"recordTiming": true
},
"@ryantam626/jupyterlab_code_formatter:settings": {
"formatOnSave": true
}
}
Enable server extensions
jupyter serverextension enable panel.io.jupyter_server_extension
Creates /home/jupyter-USER/.jupyter/jupyter_notebook_config.json
{
"NotebookApp": {
"nbserver_extensions": {
"panel.io.jupyter_server_extension": true
}
}
}
Rebuild
jupyter lab build
config.py
c.ServerApp.jpserver_extensions = {
"jupyterlab": True,
"jupyterlab_code_formatter": True,
}
Jupyter hub
mamba install jupyterhub
jupyterhub --generate-config
sudo journalctl -u jupyterhub
Strip out the jupyter- part from usernames in tljh
myauthenticator.py
from firstuseauthenticator import firstuseauthenticator
class MyAuthenticator(firstuseauthenticator):
"""Remove the jupyter- prefix from usernames"""
async def authenticate(self, handler, data):
username = data["username"]
password = data["password"]
return username.split("-")[1]
setup.py
from setuptools import setup
setup(
name="myauthenticator",
install_requires=["firstuseauthenticator"],
)