Relative path resolution fails for Kaggle Notebooks when moving from local IDE
0 reputation · 08 Sept 2025, 23:22 UTC
When developing a Kaggle Notebook locally, data files are often accessed with relative paths such as ../input/file.csv or ./data/file.csv. The same notebook, when uploaded to the Kaggle platform, encounters a FileNotFoundError because the platform does not expose the parent directory and expects the exact /kaggle/input//file.csv path.
The goal is to write a single notebook that executes successfully both in a local Jupyter environment and on Kaggle without modifying the file‑reference statements. Constraints include Kaggle’s read‑only /kaggle/input mount, the inability to create symlinks or alter the filesystem, and the need to avoid hard‑coding machine‑specific absolute paths.
What is the recommended way to reference input files so that the same notebook works locally and on Kaggle without code changes? Can an environment variable such as KAGGLE_INPUT_DIR be used to transparently rewrite relative paths at runtime? Is there a supported startup hook or notebook configuration that remaps local relative paths to the Kaggle input mount when the notebook runs on the platform?