{
  "id": 19662960,
  "title": "FileNotFoundError: [Errno 2] No such file or directory (Fix)",
  "url": "https://urgent.news/2026/11/12/filenotfounderror-errno-2-no-such-file-or-directory-fix",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-12T14:47:10.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/primeemre/filenotfounderror-errno-2-no-such-file-or-directory-fix-4fm"
  },
  "original_language": "en",
  "account": "When you run your Python script, it may encounter a FileNotFoundError: [Errno 2] No such file or directory. This error occurs when Python tries to open a file, but it can't find the specified file at the given path. Here are six common causes of this error and their respective fixes:\n\n1. You ran Python from a different folder: If you execute your script from a folder that is not the one containing the file, Python will look for the file in the wrong location. To fix this, ensure that you run the script from the same folder as the file or build the path correctly using Python's pathlib module.\n\n2. Typo in the file name: A simple typo in the file name, such as using the wrong spelling or capitalization, can cause this error. Double-check the file name and make sure it matches the actual file name in the folder.\n\n3. Windows hides the real file extension: On Windows, some file types have a default extension appended to the filename. For example, a file named \"notes.txt\" might be stored as \"notes.txt.txt\". To resolve this, either rename the file to remove the extra extension or modify the code to use the correct file name, including any additional extensions.\n\n4. Writing to a non-existent folder: When you attempt to write to a file using the 'w' mode, Python creates the file but also creates any missing folders in the path. If the folder does not exist, a FileNotFoundError will occur. To fix this, create the missing folders before writing to the file. You can use the mkdir() method with exist_ok=True or parents=True to create the folder structure.\n\nBy understanding these common causes and applying the provided fixes, you can effectively troubleshoot and resolve the FileNotFoundError: [Errno 2] No such file or directory error in your Python programs.",
  "summary": "You run your script. Python stops and prints this: FileNotFoundError: [Errno 2] No such file or directory: 'data.txt' But the file is sitting right there in your folder. So what's going on? Below are the six causes behind this error in real programs. Each one has the exact message it gives and a fix. I ran every example on Python 3.11, 3.12 and 3.14 on Windows. All three print the same message.…",
  "key_points": [
    "Running script from wrong folder causes FileNotFoundError",
    "Typos in file names lead to No such file or directory error",
    "Windows hides file extensions, causing path issues"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}