0

When I run my script from the IDE I don't get a problem. But when I run it using python -m cProfile <script_file_name> it raises a FileNotFoundError?


import pandas as pd

x = pd.read_excel(<file_name>)
petezurich
  • 9,280
  • 9
  • 43
  • 57
Ell
  • 51
  • 6

2 Answers2

0

As @Grady Player mentioned in the comment, it's probably a relative path issue.

First of all, try the file's full path; for example: "D:\some_folder\a.xlsx"

If it works, it means you are setting the path wrongly at first place.

Then, you may try to run following code for learning your IDE's working directory.

#importing the os module
import os

#to get the current working directory
directory = os.getcwd()

print(directory)

It surely gives you an idea about the relative path, so that you can create the relative path correctly.

Also, you can check this post about the FileNotFoundError.

stuck
  • 1,477
  • 2
  • 14
  • 30
  • when I try to print the directory, it prints the right directory of where the file is located in, but when it runs it says the file is not found – Ell Jun 16 '22 at 11:29
  • Did you try to give full path at first place? – stuck Jun 16 '22 at 11:33
0

I managed to find a way solution from Youtube (Channel Name: mCoding) :

import cProfile, pstats, pandas

with cProfile.Profiel() as pr:
    pandas.read_excel(<File_Name>)


stats = pstats.Stats(pr)
stats.dump_stats(filename="<stats_file_name>.prof")

and in the terminal do:

snakeviz <stats_file_name>.prof
Ell
  • 51
  • 6