FileNotFoundError: [Errno 2] No such file or directory. Yes, I'm using relative path

As @Goyo has pointed out, there’s a difference between forward and backward slashes. I can get Streamlit to read file paths correctly with either one in my local environment, but it requires forward slashes in the cloud environment.

import streamlit as st
import pandas as pd


try:
    st.write('Trying with back slashes')
    st.dataframe(pd.read_csv(r'.\\files\\test.csv'))
except:
    st.write('It didn\'t work with back slashes.')


try:
    st.write('Trying with forward slashes')
    st.dataframe(pd.read_csv(r'files/test.csv'))
except:
    st.write('It didn\'t work with forward slashes.')

Local Result

image

Streamlit Cloud Result

image

1 Like