Python
FileNotFoundError: [Errno 2] No such file or directory
FileNotFoundError
Python tried to open a file that doesn't exist at the given path.
Common Causes
- Wrong path or filename
- File not yet created
- Working directory different from expected
- Path uses wrong separators
Fixes
- 1. Use pathlib for cross-platform paths
from pathlib import Path p = Path('dir') / 'file.txt' - 2. Check before opening
if Path(path).exists(): with open(path) as f: ... - 3. Use absolute path
path = Path(__file__).parent / 'data.json'
Still not fixed?
- • Search the exact error message on Stack Overflow or GitHub Issues
- • Check the official docs for the language or tool
- • Ensure your versions (Node, Python, npm, Docker) are up to date
- • Try in a minimal reproduction (new project, single file)
Related Errors
DuskTools That Might Help
All Errors
JavaScript Heap Out of MemoryModuleNotFoundErrorAddress Already in UseIndentationErrorCannot Find ModulePeer Dependency WarningCORS Policy BlockedTypeError: 'NoneType' Not SubscriptableMerge ConflictDocker Port Already AllocatedENOENT: No Such File or DirectoryKeyErrorMaxListenersExceededWarningRecursionErrorDetached HEAD StateEACCES: Permission DeniedValueErrorNo Space Left on DeviceERR_REQUIRE_ESM