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?
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') opt.solve(model)
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.