Binary file issue

I am new to streamlit. I have my app that is working locally on my computer but I am having some issues to deploy it . Seems to have some issues with my model saved as a binary file “randam_forest.bin”

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 354, in _run_script
    exec(code, module.__dict__)
  File "/app/my_first_streamlit_app/app/main.py", line 2, in <module>
    from model_page import show_model_page

  File "app/model_page.py", line 18, in <module>

    dv, model = load_model()

  File "app/model_page.py", line 15, in load_model

    with open('random_forest.bin', 'rb') as f_in:

FileNotFoundError: [Errno 2] No such file or directory: 'random_forest.bin'

2021-12-13 16:00:56.710 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 354, in _run_script

    exec(code, module.__dict__)

  File "/app/my_first_streamlit_app/app/main.py", line 2, in <module>

    from model_page import show_model_page

  File "app/model_page.py", line 18, in <module>

    dv, model = load_model()

  File "app/model_page.py", line 15, in load_model

    with open('random_forest.bin', 'rb') as f_in:

FileNotFoundError: [Errno 2] No such file or directory: 'random_forest.bin'

2021-12-13 16:37:15.554 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 354, in _run_script

    exec(code, module.__dict__)

  File "/app/my_first_streamlit_app/app/main.py", line 2, in <module>

    from model_page import show_model_page

  File "app/model_page.py", line 18, in <module>

    dv, model = load_model()

  File "app/model_page.py", line 15, in load_model

    with open('random_forest.bin', 'rb') as f_in:

FileNotFoundError: [Errno 2] No such file or directory: 'random_forest.bin'

Hi @Tso,

First, welcome to the Streamlit community! :partying_face: :partying_face: :partying_face: :star2:

Without a link to your GitHub repo to look at your file structure, I will only be able to give you a possible reason as to why this is happening.

Usually, an error like this occurs when the file paths in your repo are different than they are locally and/or you have a lot of sub-directories.

Your Streamit script is run from the top directory of the repo, so If you have many sub-directories with different python modules, data files etc… you will have to change your script to have the paths to files as if they are running from the top dir.

Happy Streamlit-ing
Marisa

Hi Marisa,
Please here is the link of my repo. it’s public https://github.com/tantiboro/my_first_streamlit_app

thank you

Hi @Tso,

So the structure is the issue with your app. Your main repo has a sub-directory with all your python and app files including the data you’re trying to import.

At any time when you have this and are deploying on the cloud, you will have to change the file path in your python script to reflect that your app is being run from the directory above (the root GitHub directory).

So in your example when you reference your random_forest.bin you will have to use app/random_forest.bin.

Happy Streamlit-ing!
Marisa

1 Like

Thank you very much. Did fid it