Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Python IOError: [Errno 2] No such file or directory: 'data.csv' [duplicate]

Tags:

python

errno

In Python, I have a script, I'm trying to use the python open("data.csv") command to open a CSV file that I have in the Python script directory.

There is a file there called data.csv.

The python script indicates an error:

Error in Python IOError: [Errno 2] No such file or directory: 'data.csv'

What does this error mean and how do I fix it?

Here is the minimal code in the script that reproduces the error:

open("data.csv")
like image 611
Doug Fir Avatar asked Oct 21 '12 17:10

Doug Fir


People also ask

How do I fix Errno 2 No such file or directory in Python?

The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path. In the above code, all of the information needed to locate the file is contained in the path string - absolute path.

Can't open file Errno 2 No such file or directory?

The Python "FileNotFoundError: [Errno 2] No such file or directory" occurs when we try to open a file that doesn't exist in the specified location. To solve the error, move the file to the directory where the Python script is located if using a local path, or use an absolute path.

What does Errno 2 mean Python?

The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check that you are referring to the right file or folder in your program. Answered by.

What does FileNotFoundError Errno 2 No such file or directory mean?

The error FileNotFoundError Errno 2 no such file or directory occurs when Python cannot find the specified file in the current directory.


1 Answers

Try to give the full path to your csv file

open('/users/gcameron/Desktop/map/data.csv')

The python process is looking for file in the directory it is running from.

like image 127
Senthil Kumaran Avatar answered Oct 12 '22 12:10

Senthil Kumaran