Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raveenb/a9c8e17490fa312cfccdd5f8d3faf4c8 to your computer and use it in GitHub Desktop.
Save raveenb/a9c8e17490fa312cfccdd5f8d3faf4c8 to your computer and use it in GitHub Desktop.
Awesome JupyterLab Installation and Customizations (Python 3.11)
from loguru import logger
import requests
import httpx
import pandas as pd
import numpy as np
import asyncio
from typing import List, Dict, Optional, Tuple, Text, Union
from pydantic import BaseModel, conlist, constr, conint
import json
from rich import pretty, print
pretty.install()
import jupyter_black
jupyter_black.load()
#!/bin/bash
source logs.sh
read -p "Pick Python verion 3.9/3.10/(3.11 default): " python_version
if [ -z "$python_version" ]; then
python_version="3.11"
warn "As no selection was made, using Python $python_version"
fi
if [ -d "venv$python_version" ]; then
error "Python v$python_version Virtual Env Exists, Delete it before setting up"
exit
fi
info "Setting up Jupyterlab with Python v$python_version Virtual Env"
deactivate
if ! $("python$python_version" -m venv "venv$python_version"); then
error "Unable to create Python $python_version Virtual Environment, Exiting"
exit 1
fi
info "Activating Python v$python_version Virtual Env"
source "venv$python_version/bin/activate"
info "Installing Jupyterlab"
pip install pip setuptools wheel pip-tools pip-autoremove --upgrade
pip-compile --upgrade
pip-sync
pip install openpyxl
info "Installing Jupyter Extensions and Widgets"
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install luxwidget
info "Installing Javascript Kernel in Jupyterlab"
warn "This will take some time..."
npm install --location=global npm yarn
npm install --location=global ijavascript
ijsinstall --spec-path=full
jlpm add --dev typescript-language-server
info "Deactivating v$python_version Virtual Env"
deactivate
info "Installing a few Config Files"
cp jupyter_00_start.py ~/.ipython/profile_default/startup/00_start.py
info "Installing a few Fonts"
brew install font-fira-mono-nerd-font
info "Additional Recommended Settings in Jupyterlab"
warn "1. Document Manager - Autosave Documents -> 30s"
warn "2. Extension Manager - Enabled Status(Check), Disclaimed Status(Check)"
warn "3. File Browser - Navigate to current directory(Check)"
warn "4. Jupyter Widgets - Save Jupyter widget state(Check)"
warn "5. Notebook - Auto Closing Brackets(Checked), Font Family(MonoLisa), Font Size(15), Line Height(1.6), Show Line Numbers(Check), Match Brackets(Check), Code Folding(Check), Show Trailing Space(Check), Shut down Kernel(Check), Word Wrap Colum(88)"
warn "6. Status Bar - Status Bar Visibility(Check), Start Mode(Single)"
warn "7. Terminal - Font Family(FuraMono Nerd Font), Font size(13), Line Height(1), Shut down on close(Check)"
warn "8. Theme - Selected Theme(Darcula), content-font-family(SF Mono), content-font-size1(13), ui-font-family(SF Mono), ui-font-size1(13)"
warn "9. Code Completion - Continous Hinting(Check), "
success "Finished"

JupyterLab Installation and Customizations (Python 3.11)

Make your JupyterLab awesome with Code Completion, Code Typeahead, Font Changes for Code/UI/Output, Faster Autosave, Black Autoformatting, Ruff Lint Suggestions, Rich Pretty Printed REPL Outputs, Darcula Theme, Autoversion of files, Pandas Lux Visualization, Javascript Kernel and more.

General Instructions

  1. Download the zip file of this gist. Unzip the zip file to a directory and give execution rights to the .sh files using chmod +x *.sh
  2. Ensure you are running on a mac and have homebrew installed
  3. Ensure you have python(3.9, 3.10, 3.11) installed and is available in the default path. Otherwise, install the versions you want, using brew install python@3.9 or brew install python@3.10 or brew install python@3.11

Installing JupyterLab

Run ./jupyterlab_install.sh and pick the version of python you want. Enter 3.9, or 3.10 or 3.11. You can just hit enter to pick the default, which is Python 3.11

Rest is fairly automated. There are some suggested fonts and customizations. I recommend you go thru them, it will make your Jupyter experience good. You will now have a virtual environment with the version of Python you want and JupyterLab will be installed in it.

Running JupyterLab

Run ./jupyterlab_run.sh to start JupyterLab with the Python version you want. Assuming, you have installed the version in the first place using the above script. Enter 3.9, or 3.10 or 3.11. You can just hit enter to pick the default, which is Python 3.11

Updating JupyterLab

Run ./jupyterlab_update.sh to update JupyterLab and all its dependent libraries to the latest version. Enter 3.9, or 3.10 or 3.11. You can just hit enter to pick the default, which is Python 3.11

Warning: I use pip-tools to ensure there is no version mismatch. But pip-tools will remove any manually installed libraries. This may be good or bad depending on your case. If you want to keep your JuputerLab setup uncluttered and clean without old dangling unused libraries like pytorch that take up a lot of space, this may be the way to do it. Later, when you need to use earlier notebooks, then just %pip install the required libraries in the notebook at that time.

Custom Fonts

Font MonoLisa is a paid font, that I use and will recommend. I am also thinking of Gintronic but I am wondering if the cost(150 Euros) is justified. But IMHO, custom Fonts make a lot of difference if you are spending a lot of time infront of code and coding is your profession. Get the best tools for your job.

My usual coding font setup is at present like this (unfortunately none of them are OSS):

  • Code Font - Monolisa, Size(13 or 15 pt, depending on screen size), Line Height(1.618), Ligatures(Enabled)
  • IDE UI Font - SF Mono, Size(13), Line Height(1.4), Ligatures(Disabled)
  • Logs/Other Content/Execution Results - Input Mono, Size(13), Line Height(1.0), Ligatures(Disabled)
#!/bin/bash
source logs.sh
read -p "Pick Python verion 3.9/3.10/(3.11 default): " python_version
if [ -z "$python_version" ]; then
python_version="3.11"
warn "As no selection was made, using Python $python_version"
fi
if [ ! -d "venv$python_version" ]; then
error "Python v$python_version Virtual Env dont exists, Install it first"
exit
fi
info "Activating Python $python_version Virtual Env"
source "venv$python_version/bin/activate"
info "Starting Jupyterlab"
jupyter lab
info "Deactivating Python $python_version Virtual Env"
deactivate
success "Stopped Jupyterlab"
#!/bin/bash
source logs.sh
read -p "Pick Python verion 3.9/3.10/(3.11 default): " python_version
if [ -z "$python_version" ]; then
python_version="3.11"
warn "As no selection was made, using Python $python_version"
fi
if [ ! -d "venv$python_version" ]; then
error "Python v$python_version Virtual Env dont exists, Install it first"
exit
fi
info "Activating Python v$python_version Virtual Env"
source "venv$python_version/bin/activate"
info "Updating Jupyterlab"
pip install pip setuptools wheel pip-tools pip-autoremove --upgrade
pip-compile --upgrade
pip-sync
pip install openpyxl
info "Installing Jupyter Extensions and Widgets"
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install luxwidget
info "Updating Javascript Kernel in Jupyterlab"
warn "This will take some time..."
npm install --location=global npm yarn
npm install --location=global ijavascript
ijsinstall --spec-path=full
jlpm add --dev typescript-language-server
info "Deactivating v$python_version Virtual Env"
deactivate
success "Finished"
#!/bin/bash
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
LIME_YELLOW=$(tput setaf 190)
YELLOW=$(tput setaf 3)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
function warn() {
echo "${YELLOW}WARNING: $1${NORMAL}"
}
function info() {
echo "${BLUE}INFO: $1${NORMAL}"
}
function error() {
echo "${RED}ERROR: $1${NORMAL}"
}
function success() {
echo "${BRIGHT}${GREEN}SUCCESS: $1${NORMAL}"
}
# jupyterlab related
jupyterlab
jupyterlab-lsp
ipywidgets
jupyter-black
rich[jupyter]
jupyterlab_autoversion
# python language server related
python-lsp-server[all]
pylsp-mypy
pyls-isort
pyls-memestra
pylsp-rope
python-lsp-black
python-lsp-ruff
# commonly used libraries
loguru
requests
httpx[http2]
pandas
matplotlib
seaborn
pydantic
more-itertools
lux-api
tqdm
theme-darcula
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment