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")
open looks in the current working directory, which in your case is ~
, since you are calling your script from the ~
directory.
You can fix the problem by either
cd
ing to the directory containing data.csv
before executing the script, or
by using the full path to data.csv
in your script, or
open
and os.listdir
) may be affected by this.It's looking for the file in the current directory.
First, go to that directory
cd /users/gcameron/Desktop/map
And then try to run it
python colorize_svg.py
You need to either provide the absolute path to data.csv, or run your script in the same directory as data.csv.
Source: Stackoverflow.com