0

Simple 2 line Python code is :

import pandas as pd 

pd.read_excel('sample.xlsx')

The above code runs fine when I go to the location of this folder & run from cmd but the same directory has the IDLE. When I use IDLE to run the same code it throws FileNotFoundError

Can anyone suggest where I am making mistake.

lupaulus
  • 358
  • 5
  • 22
Rohit Patil
  • 49
  • 1
  • 9
  • Better use an absolute path to the file. – Michael Butscher May 17 '20 at 08:03
  • looks like your working directory is set to a different directory. you might want to look at this thread: https://stackoverflow.com/questions/15821121/whats-the-working-directory-when-using-idle – Almog-at-Nailo May 17 '20 at 08:05
  • Don't use relative file paths unless you used `os.chdir` or the like to set the working directory to something you *know* makes the relative path correct. – chepner May 17 '20 at 13:26
  • If you start IDLE with `python -m idlelib` in the directory containing that data file, rather than with an icon or Start entry, then python will find the file. – Terry Jan Reedy May 19 '20 at 12:10

1 Answers1

0

Very Basic mistake.

Right clcik on the idle and goto properties.

Goto --> Shortcut --> Start in : "--------"

This is your default directory where the python is is trying to search the file. Change this directory to the folder where you want the python to search you file.

I recommend to change this directory since you will work on many scripts which you would not want to be stored in default installation directory. Better create a seperate folder and give Kudos.

lupaulus
  • 358
  • 5
  • 22
Rohit Patil
  • 49
  • 1
  • 9