Filenotfounderror: [errno 2]

Hi,

Am trying to run one of the Guided Projects locally in Jupyter Notebook.
And in spite of mentioning the complete path of the file (while loading the data), I still get filenotfounderror: [errno 2] error.

Any help?!

That’s odd.

Can you run the following and share the output?

import os

dir = "D:\D Drive\Data Quest_Guided Projects\Project 6\\"
print(os.listdir(dir+"dete_survey.csv"))

Can you also post some convincing proof that this is happening? For example, you can record a gif of your notebook with the explorer opened on the appropriate directory and run that code in a notebook.

1 Like

Hi @Datom,

Also, Can you try replacing / with \\? That is two backslashes? Let me know how that goes.

Thanks,
Sahil

@Bruno, @Sahil Thanx for the help guys!!

Placing r before the path worked!!

2 Likes

When you open a file with the file name , you are telling the open() function that your file is in the current working directory. This is called a relative path. If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. A good start would be validating the input. In other words, you can make sure that the user has indeed typed a correct path for a real existing file, like this:

while not os.path.isfile(fileName):
    fileName = input("No such file! Please enter the name of the file you'd like to use.")

Another way to tell the python file open() function where your file is located is by using an absolute path, e.g.:

f = open("/Users/foo/filename")