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