import os
file_path = "/User/c2c/Desktop/raw_data.csv"
with open(file_path, "r") as file:
for line in file:
print(line.strip())
Error:
---------------------------------------------------------------------------
FileNotFoundError
Traceback (most recent call last)
<ipython-input-7-77369353dc39> in <cell line: 5>()
3 file_path = "/User/c2c/Desktop/raw_data.csv"
4
----> 5 with open(file_path, "r") as file:
6 for line in file:
7 print(line.strip())
FileNotFoundError: [Errno 2] No such file or directory: '/User/c2c/Desktop/raw_data.csv'
![FileNotFoundError- [Errno 2] No such file or directory - Python](https://code2care.org/q/fix-filenotfounderror-error-2-no-such-file-or-directory-python/images/FileNotFoundError-%20%5BErrno%202%5D%20No%20such%20file%20or%20directory%20-%20Python.jpg)
![FileNotFoundError- [Errno 2] No such file or directory - Terminal](https://code2care.org/q/fix-filenotfounderror-error-2-no-such-file-or-directory-python/images/FileNotFoundError-%20%5BErrno%202%5D%20No%20such%20file%20or%20directory%20-%20Terminal.jpg)
Reason for FileNotFoundError Exception
The reason for the FileNotFoundError exception in Python is that the file or directory that you are trying to open does not exist.
How to fix FileNotFoundError Exception
- Is the file name specified correctly?
- Is the extension (.txt, .csv, .xlsx, etc)of the file correct?
- Is the path of the file specified correctly?
- File name and path are case sensitive, so do they match?
- Do you have permission to read the file?
- If reading the file from a remote location, make sure there are no network issues.
Below are some area's that you should investigate to fix this issue.
Reference:
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!