Joe
Joe

Reputation: 12417

Code running on PyCharm, but not Jupyter

I have to open an excel file, and I do in this way:

 xl_file = pd.ExcelFile('D:\mypath\myFile.xls')

On PyCharm(Python 2.7.8) it works perfectly, but on Jupyter(Python 3), I've always this error:

FileNotFoundError: [Errno 2] No such file or directory

What could be the reason?

Upvotes: 1

Views: 786

Answers (2)

Joe
Joe

Reputation: 12417

After having changed the Jupyter start folder as suggested in this post how to change jupyter start folder? , if the files are in this folder, to load them it isnt necessary to write the path. This is enough:

xl_file = pd.ExcelFile('myFile.xls')

Upvotes: 0

amanbirs
amanbirs

Reputation: 1108

This might happen if you call jupyter notebook at a place other than your root directory. In this case, jupyter might not have access to the file.

Try going to D: and calling jupyter notebook and then retrying this. Another option is to get the path of your notebook using:

os.path.abspath("__file__")

and then setting a relative path to the dataset.

Edit:

Let's say you want to set a path one level above the directory that contains the notebook. Then you would do:

foo = os.path.dirname(os.path.abspath("__file__"))
relative_path = os.path.join(foo, '..')

Upvotes: 1

Related Questions