FileNotFoundError 🐍 Python

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

  1. Use Path(__file__).parent / "data.csv"
  2. Print os.getcwd() to see where Python looks
  3. Use raw strings on Windows: r"C:\data\file.csv"

Detailed fix by platform

Python

  1. python
    from pathlib import Path
    DATA = Path(__file__).resolve().parent / "data" / "input.csv"

How to diagnose

  1. Path — Exact path in the message
  2. CWD — os.getcwd()
  3. 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.