Home Directory changes on the deployed app

Hi Streamlit Community,

I have built an app that as part of it should save a file on the home directory using pathlib or os functions.

It works properly and create the path with no issues on the local app but when I deploy the app, the path will be changed with an error:

FileNotFoundError: [Errno 2] No such file or directory: ‘/home/appuser/Downloads/WeatherAnalysis-Brisbane.docx’

Basically, the home directory part (C:/Users/{Username}/) is replaced with (/home/appuser/) which I guess there should be something wrong with dependencies but couldn’t find the cause.

here is the requirements.txt content:



Your error message rather suggests that it is a simple path problem, you may be using the wrong relative paths. Also, never use absolute paths!

But for that we would need to see the actual file structure, best you share the link to your public github repo.

Thanks @Franky1 for the reply.

If its an error with the path it shouldn’t also work on the local app. It only happens when I deploy the app. And yes, its not an absolute path to my knowledge, it takes the user home directory, and then ‘Downloads’ folder which is a default folder on Windows for any users, and saves the word file (using python-docx) with the given name based on the user selection will be modified. I cant share the github link as it is a private app unfortunately, but here is a summary of the code that causes the problem.

export_as_docs = st.button("Export Report (.docx)")

document = Document()

##here is a bunch of text that will be added to the file

if export_as_docs:
    filepath = pathlib.Path.home()   
    document.save(pathlib.Path(filepath,"Downloads", f'WeatherAnalysis-{global_epw.location.city}.docx'))


No, this conclusion is unfortunately not correct. It depends e.g. on which directory streamlit is started from. Accordingly, the relative paths can be different. On Streamlit Cloud afaik the Streamlit app is always launched from the root folder of the Github repository.

1 Like

Thanks for the clarification.

Can you please share an example of how would be the way to resolve this issue?


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