Invoking a Python subprocess in a deployed Streamlit app
Problem
Let's suppose you want to invoke a subprocess to run a Python script script.py in your deployed Streamlit app streamlit_app.py. For example, the machine learning library Ludwig is run using a command-line interface, or maybe you want to run a bash script or similar type of process from Python.
You have tried the following, but run into dependency issues for script.py, even though you have specified your Python dependencies in a requirements file:
```python
streamlit_app.py
import streamlit as st
import subprocess
subprocess.run(["python", "script.py"])
```
Solution
When you run the above code block, you will get the version of Python that is on the system path—not necessarily the Python executable installed in the virtual environment that the Streamlit code is running under.
