Expose executables from path to streamlit/scope?

Hello! I am a huge fan of this project. I am trying to build an optimization model using pyomo and streamlit. I am having trouble with understanding how the path works in streamlit. How do I expose path executables to streamlit? e.g. cbc for my use case?

1 Like

Hey @infvie, welcome to Streamlit!

To use pyomo inside a Streamlit app, you could do something like this:

import pyomo.environ as pyo
import streamlit as st

opt = pyo.SolverFactory('cbc')

If you need your Streamlit app run a path executable directly, then you probably want to check out the Python subprocess module. For example:

import subprocess
import streamlit as st

result = subprocess.run(['pyomo', 'solve', 'my_model.py', '--solver="cbc"'])
st.write(result.stdout)  # Do something interesting with the result

For utilities that have both a Python library and a command line interface, like pyomo, it’s generally easier to use the Python API. Use the subprocess module only when you have to.

Hi @infvie

I’m a great fan of pyomo. It’s such a joy to develop models in.

If at all possible please share your app or some refactored version. I would really like to share it in the gallery at awesome-streamlit.org if I can and may.