Ell
Ell

Reputation: 29

Raising FileNotFoundError when running script through SnakeViz

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>)

Upvotes: 0

Views: 159

Answers (2)

Ell
Ell

Reputation: 29

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

Upvotes: 0

stuck
stuck

Reputation: 1570

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.

Upvotes: 0

Related Questions