Run your full Python project in Google Colab without breaking paths
Most examples show small Colab notebooks with a few cells, but real ML work means full projects: multiple scripts, data folders, models, and utilities. This guide shows how to run an entire Python project on Colab without file path chaos – and how to keep it reproducible.
1. Put your project in a single folder
my-python-project/
src/
__init__.py
train.py
utils.py
notebooks/
colab_entrypoint.ipynb
data/
raw/
processed/
models/
requirements.txt
README.md
Push this to GitHub or store it in Google Drive under MyDrive/projects/.
2. Mount Drive and change working directory
from google.colab import drive
drive.mount('/content/drive')
PROJECT_ROOT = "/content/drive/MyDrive/projects/my-python-project"
%cd $PROJECT_ROOT
Now src/, data/, and notebooks/ exist under a stable root, and you can
import modules from src.
3. Install dependencies in the Colab runtime
From the notebook:
!pip install -r requirements.txt
Colab uses a fresh environment, so this step must run whenever the runtime resets. Put it near the top of your notebook.
4. Run project scripts from the notebook
You can either:
- call Python scripts using
!python, or - import functions from
src/and call them directly.
# Option 1: run training script !python src/train.py --config configs/baseline.yaml
# Option 2: import & call
import sys
sys.path.append("src")
from train import run_experiment
run_experiment(config_path="configs/baseline.yaml")
5. Keep data paths relative to PROJECT_ROOT
Inside your code, avoid absolute paths like C:\Users\.... Use:
from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[1] DATA_DIR = PROJECT_ROOT / "data" / "raw"
This works both locally and in Colab (as long as you cd into PROJECT_ROOT first).
6. Use NoteCapsule for project snapshots
Once the project runs end-to-end in Colab, create a Capsule so others can reproduce the run later without asking you for “that exact environment”.
from notebookcapsule import create_capsule
create_capsule(
name="colab_full_project_run",
notebook_path="notebooks/colab_entrypoint.ipynb",
data_dirs=["./data", "./models"],
base_dir=".", # project root
)
Share the Capsule with your repo so collaborators know exactly which data and environment were used for a given run.
Running full projects in Colab doesn’t have to feel fragile
NoteCapsule helps you turn a working Colab project into a reproducible Capsule – so you can hand it to a teammate, reviewer, or future self and trust that it will still run.
Join NoteCapsule early accessWe’re building tools specifically for notebook-heavy projects that need to survive beyond one Colab session.