Recently, while building a web scraper app with Streamlit, I ran into a frustrating error:
ModuleNotFoundError: No module named 'selenium'
I had already installed selenium using pip install -r requirements.txt, and even confirmed it was installed using:
pip show selenium
and
pip list
Still, Streamlit was throwing the error.
π΅οΈββοΈ The Clue
To investigate, I added a simple debug line at the top of my main.py file:
import sys
print("Running from:", sys.executable)
When I ran:
streamlit run main.py
The output showed that Streamlit was running from a different Python environment β not the virtual environment where selenium was installed.
β The Fix
It turned out that I simply hadnβt activated the virtual environment before launching Streamlit. Hereβs what finally worked:
source env/bin/activate
streamlit run main.py
Once I activated the correct virtual environment, everything worked as expected.
π‘ Takeaway
If you ever install a package but your Python app can’t find it, the issue might not be the install itself β but which Python interpreter is being used. Checking sys.executable is a quick way to diagnose mismatched environments.