1. Why JupyterLab Instead of Notebooks?
Classic Jupyter Notebook is a great playground for exploration, but it has limitations:
- Only one notebook at a time (clunky when switching).
- No integrated terminal or editor.
- Poor extension management.
- Harder to manage big DS projects.
JupyterLab solves these by being:
- A modular IDE (like VS Code but inside the browser).
- Multi-document: run several notebooks side-by-side.
- Integrates Git, terminals, debuggers, and visualizations.
- Fully extensible → install plugins for ML, visualization, and workflows.
2. Installation & Setup
Install JupyterLab
# Using pip pip install jupyterlab # Using conda (recommended) conda install -c conda-forge jupyterlab
Run it:
jupyter lab
By default, it launches at http://localhost:8888/lab.
3. JupyterLab Workspace Layout
When you first open JupyterLab, you’ll see:
- Launcher → start new notebooks, consoles, terminals.
- File browser → navigate directories.
- Tabs & split views → drag notebooks into left/right panels.
- Command palette (Ctrl + Shift + C) → like VS Code’s command search.
Pro tip: Save workspace layout with Workspaces → you can reopen the same setup later.
4. Multi-Panel Productivity
- Open data exploration notebook on left, visualization notebook on right.
- Add a terminal below for running experiments:
python train_model.py --epochs 10 --batch 32
- Open a Markdown editor in another panel for documentation.
This makes JupyterLab a true research workstation.
5. Integrated Terminal & Shell Magic
Run Linux commands inside cells with !:
!ls -lh data/ !pip install seaborn
Or open a full terminal tab (better for workflows like git, conda, dvc).
Example: Version control from inside JupyterLab:
git checkout -b experiment/xgboost git add notebooks/xgb_experiment.ipynb git commit -m "Try XGBoost with tuned params"
6. Extensions: Supercharging JupyterLab
a) Variable Inspector
pip install lckr-jupyterlab-variableinspector
Lets you inspect variables in a sidebar: names, dtypes, shapes, memory usage.
b) Git Integration
pip install jupyterlab-git jupyter lab build
Gives a GUI for Git: commit, push, checkout branches → all inside JupyterLab.
c) Plotly & Bokeh
Interactive visualizations inside notebooks.
pip install jupyterlab-plotly
d) TensorBoard in JupyterLab
pip install jupyterlab_tensorboard
Launch TensorBoard directly in a panel → monitor training runs in real time.
7. Debugging Inside JupyterLab
Enable debugger with ipykernel:
pip install ipykernel
Then → Debug panel appears.
- Set breakpoints.
- Inspect variables.
- Step through execution line by line.
Much better than just throwing in print() everywhere.
8. Keyboard Shortcuts & Productivity
Common Shortcuts
- Shift + Enter: run cell
- Ctrl + Shift + -: split cell
- A: insert above
- B: insert below
- M: change to Markdown
- Y: change to Code
Customize Shortcuts
Settings → Advanced Settings Editor → Keyboard Shortcuts
Example: remap Run All Cells to Ctrl + Shift + R.
9. Configurations & Project Setup
Organize data science projects like this:
project/ │── notebooks/ │ ├── EDA.ipynb │ ├── model_experiment.ipynb │── src/ │ ├── data_loader.py │ ├── train.py │── data/ │ ├── raw/ │ └── processed/ │── results/ │── environment.yml
Load .env settings in JupyterLab using python-dotenv:
from dotenv import load_dotenv
import os
load_dotenv()
API_KEY = os.getenv("API_KEY")
10. Exporting Notebooks
To HTML/PDF/Markdown
jupyter nbconvert --to html notebook.ipynb jupyter nbconvert --to pdf notebook.ipynb
Great for sharing results with non-technical teammates.
To Scripts
jupyter nbconvert --to script notebook.ipynb
This is the first step in refactoring into production code.
11. Best Practices for JupyterLab
- Keep notebooks modular → one per experiment, not 1000 cells in one.
- Use Markdown cells → document your thinking as you go.
- Pin environments with conda env export.
- Use Git + DVC → don’t store raw 10GB datasets in notebooks.
- Refactor code into scripts after experiments (see Tutorial 4).
12. Advanced Tips
- Use %%timeit for benchmarking code snippets.
- Magic %matplotlib inline vs %matplotlib widget for interactive plots.
- Use papermill to parametrize notebooks and run them as pipelines.
Example with papermill:
papermill train_model.ipynb output.ipynb -p epochs 50 -p lr 0.01