pip installed into a different Python than the one running the script
A system can easily have several Pythons — system, conda, venv, plus whatever the workflow or notebook uses. pip install X installs into whichever pip is first on PATH, which is often not the interpreter that then runs your code.
Tie them together: python -m pip install X uses the same interpreter you are running. To confirm, print sys.executable from inside the failing script — that is the Python that matters, and it is frequently a surprise.