FileNotFoundError: [Errno 2] No such file or directory: 'static/player_stats_initial.csv'

def analyze_using_old_season_data(max_players_from_team, transfer, wildcard, gw, budget):
player_df = pd.read_csv(ā€˜static/player_stats_initial.csvā€™)
teams_df = pd.read_csv(ā€˜static/teams.csvā€™)
injured_players_df = get_injured_player_list()

Hello @Manandeep_Singh, welcome to the forum!

Is your static folder located at the same location as your streamlit app script?

Yes it is located in the same location

And do you run streamlit in the same directory as well? (streamlit run app.py)
Or have you configured your PyCharm to run it for you?

In case you configured your run action, make sure you set your pythonProject as a working directory.

I run the app from anaconda


The error here is that you donā€™t run streamlit from your project path. When you do your streamlit run in the first screenshot, your working directory is C:/Users/HP. Therefore, when pandas tries to access static/player_stats_initial.csv, itā€™ll search that static directory in C:/Users/HP.

What you could do is go to your project directory, and run your app from there

> cd C:/Users/HP/PycharmProjects/pythonProject
> streamlit run app.py

Regarding the exception in your screenshot, you might have changed your source code since then, but the path is misformatted. If you want to hardcode a path in your code, make sure to use regular slashes / instead of backslashes \, or prepend your string with a little r like so: pd.read_csv(r'C:\Users\HP\...')

Curiously the csv path seems to be misformatted. That would explain the FileNotFoundError here, but i

Python FileNotFoundError means you are trying to open a file that does not exist in the specified directory. 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("Whoops! 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")

In any case, if your Python script file and your data input file are not in the same directory, you always have to specify either a relative path between them or you have to use an absolute path for one of them.