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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.