Common causes
- The file path is relative and your working directory isn't where you think it is
- A typo in the filename or path, including wrong case on case-sensitive systems
- The file was deleted, moved, or never created
- You're using a relative path like 'data/file.csv' but running the script from a different directory
How to fix it
- Print the current working directory to verify your location: import os; print(os.getcwd())
- Use an absolute path or build one relative to the script: os.path.join(os.path.dirname(__file__), 'data.csv')
- Check that the file actually exists: ls <path> or os.path.exists(path)
- Run the script from the directory that contains the file, or adjust the path accordingly
Example
Traceback (most recent call last):
File "app.py", line 3, in <module>
with open('data/users.csv') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'data/users.csv'Opening a CSV file with a relative path while running the script from the wrong directory
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
