How to read data from Google Drive in Google Colab (reliably)

Google Colab · Google Drive · Approx. 8 min read

“FileNotFoundError” in Colab when the file is clearly in your Drive is a classic problem. Let’s walk through the simplest, repeatable way to mount Drive and read CSVs, images, and other files without path confusion.

1. Mount Drive the right way

from google.colab import drive
drive.mount('/content/drive')

After you authorize, your Drive appears under /content/drive/MyDrive/. You can browse it from the left sidebar (Files tab → refresh).

2. Organize your project inside Drive

MyDrive/
  projects/
    my-colab-project/
      data/
        train.csv
        test.csv
      notebooks/
        experiment.ipynb
      models/

In Colab:

PROJECT_ROOT = "/content/drive/MyDrive/projects/my-colab-project"
%cd $PROJECT_ROOT

3. Read CSVs, images, and other files with relative paths

Now your notebook lives under PROJECT_ROOT, so you can use:

import pandas as pd

df = pd.read_csv("data/train.csv")

For images:

import os
from PIL import Image

img_dir = "data/images"
for fname in os.listdir(img_dir):
    img = Image.open(os.path.join(img_dir, fname))
    # process image...

4. Debug common path mistakes

5. Capture a Capsule once it works

After you’ve finally wired all your paths correctly and everything runs, take a NoteCapsule snapshot so you don’t have to rediscover these paths later.

from notebookcapsule import create_capsule

create_capsule(
    name="drive-paths-working",
    notebook_path=f"{PROJECT_ROOT}/notebooks/experiment.ipynb",
    data_dirs=[f"{PROJECT_ROOT}/data"],
    base_dir=PROJECT_ROOT,
)

This saves a Capsule with a data manifest based on your Drive paths.

Never debug the same Colab path twice

NoteCapsule helps you snapshot project state – code, environment, and data layout – so once you’ve fixed your Drive paths, you can keep them working across machines and runtimes.

Join NoteCapsule early access