Directory not found when exporting csv file in deploy mode, but it works locally

Hy, everyone

I’ve created a export csv with the following code:

path_pedidos = st.text_input('Type folder to export files', 'C:/Downloads')

if st.button('Export'):
            
        for file in os.scandir(path_pedidos):
            if file.name.endswith(".csv"):
                os.unlink(file.path)

        # create a new folder on Compras\Pedidos with the date and a subfolder with nome_pedido
        if not os.path.exists(path_pedidos+'/'+str(date.now().strftime('%Y-%m-%d'))+'/'+nome_pedido):
            os.makedirs(path_pedidos+'/'+str(date.now().strftime('%Y-%m-%d'))+'/'+nome_pedido)
            
        # EXPORT FILES
        for i in pedidos['cad_fg'].unique():
            pedidos[pedidos['cad_fg']==i][['cad_codigo','cad_cod_barra','cad_custo_medio','compra']].to_csv(path_pedidos+'/'+str(date.now().strftime('%Y-%m-%d'))+'/'+nome_pedido+'\\pedido_'+str(i)+'.csv', sep=';', decimal=',', encoding='latin_1', index=False)

User choose where to export the files and the code create a subfolder with current date and another subfolder with name of category (nome_pedido).
When I test this with streamlit run app.py, it works properly, but when I deploy it, I get the following error message:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Downloads'

It is the exactly same code and I’ve tested repeteadly and it does not work. Any ideas about the reason?

Thanks in advance for any help.

When you run the code locally with streamlit run app.py, it works because C:/Downloads exists on your local machine. However, when you deploy the app (likely on a cloud service or a different server), the folder C:/Downloads does not exist in that environment.

you can use a download button : st.download_button - Streamlit Docs

1 Like

Tnahk you very much!

I didn’t know about this button. You solved my problem. :smiley:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.