import os file_path = "/User/c2c/Desktop/raw_data.csv" with open(file_path, "r") as file: for line in file: print(line.strip())
--------------------------------------------------------------------------- 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'
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.
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
- Have you noticed MacOS Ventura About this Mac look like Mac OS X - Mac-OS-X
- Docker Alpine Linux and Apache2 Example - Docker
- Audio Video Network protocols supported by Android OS Devices - Android
- How to follow redirects in cURL Command Request - cURL
- How to hide toolbar on Notepad++ - NotepadPlusPlus
- Is Java 20 an LTS Version? - Java
- How to find files taking up space on your Mac - MacOS
- PowerShell Concatenate String Examples - Powershell