close

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

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following Error in Python IOError: [Errno 2] No such file or directory: ‘data.csv’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Error in Python IOError: [Errno 2] No such file or directory: ‘data.csv’ Error Occurs?

Today I get the following Error in Python IOError: [Errno 2] No such file or directory: ‘data.csv’ in python.

How To Solve Error in Python IOError: [Errno 2] No such file or directory: ‘data.csv’ Error ?

Solution 1

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.

Solution 2

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

  • cding to the directory containing data.csv before executing the script, orby using the full path to data.csv in your script, orby calling os.chdir(…) to change the current working directory from within your script. Note that all subsequent commands that use the current working directory (e.g. open and os.listdir) may be affected by this.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read