FileNotFoundError: [Errno 2] No such file or directory: 'data.csv'
Python couldn’t find the file at that path — usually because relative paths resolve from the working directory, not the script.
Seen on:
Python
Meaning
open('data.csv') looks in the current working directory, which differs when you run from an IDE, cron, Docker or another folder. Build paths relative to the script with pathlib.
Common causes
- Relative path + different working directory
- File not copied into the container/deploy
- Typo or case mismatch
- Windows backslashes in a string (\t, \n escapes)
⚡ Quick fix
- Use Path(__file__).parent / "data.csv"
- Print os.getcwd() to see where Python looks
- Use raw strings on Windows: r"C:\data\file.csv"
Detailed fix by platform
Python
- python
from pathlib import Path DATA = Path(__file__).resolve().parent / "data" / "input.csv"
How to diagnose
- Path — Exact path in the message
- CWD — os.getcwd()
- Exists — Is it there in this environment?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026