πŸ› Streamlit Couldn’t Find selenium β€” Even Though It Was Installed

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.

Leave a comment