Cloud streamlit won't load a .pkl file

  1. My app wonā€™t open. Source: https://share.streamlit.io/steveschneider2/pass/main/TrafficStreamlitApp.py The app (python) needs to load a ā€œpickleā€ file (which is a ML Model). I have t his app running well on my machine. Today was the first time i have connected to the streamlit cloud. The pickle file is in the same folder as the python file, and is in the Github repo from which the app loaded. So, if the pickle file was loaded (as just one of the files in the repo) ā€˜upā€™ to streamlit why can it not be located? Should i be changing the load line somehow? Below is that line: xgb1 = pickle.load(open(ā€˜FloridaTraffic2014xgb.pklā€™, ā€˜rbā€™)) Any help is appreciated. If i am asking this question in the wrong place, please re-direct me. Thanks! also, hereā€™s the error msg: File ā€œ/app/pass/TrafficStreamlitApp.pyā€, line 57, in xgb1 = pickle.load(open(ā€˜FloridaTraffic2014xgb.pklā€™, ā€˜rbā€™)) (edited)

Hi @steve_Schneider , welcome to the Streamlit community!

Can you post more of the error message, itā€™s not clear what the issue might be. You could also try setting the Python version on Streamlit Cloud; pickle requires that you use the same Python version to read the pickle as was used to write it:

Best,
Randy

randy, first, thank you for your response. Second, i deleted the app, reloaded, specifying Python 3.8. Here is the key part of the messagingā€¦

[manager] Starting up for owner: 'steveschneider2', repository: 'pass', branch: 'main', main module: 'TrafficStreamlitApp.py'
[manager] Cloning repository ...
[manager] Cloning into 'pass'...
[manager] Cloned repository!
[manager] Processing dependencies ...
[manager] Processed dependencies!
2021-10-11 18:26:11.459 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/script_runner.py", line 354, in _run_script
    exec(code, module.__dict__)
  File "/app/pass/TrafficStreamlitApp.py", line 57, in <module>
    xgb1 = pickle.load(open('FloridaTraffic2014xgb.pkl', 'rb'))
ModuleNotFoundError: No module named 'xgboost'



[client] Connecting...

ModuleNotFoundError: No module named ā€˜xgboostā€™

So it looks like the issue isnā€™t actually the pickle, but that you are missing a dependency in your requirements file. Which in your case doesnā€™t actually exist.

Create a file named requirements.txt, and place the packages you need to install into that. If you install pipreqs LOCALLY, you can generate the requirements.txt file you need. Commit that to your GitHub repo and you should be all set.

Best,
Randy

1 Like

Randy, thanks much for your assistance. It is now up and running. Have a GREAT day!

2 Likes

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