ModuleNotFoundError: No module named 'selenium'
Fixes the plain missing-module error for Selenium. Use when `from selenium import webdriver` fails with ModuleNotFoundError naming selenium. Not for chromedriver PATH errors (import already worked) or webdriver shadowing import errors.
The selenium package is not installed in the Python running your script. Run python -m pip install selenium and the import works. If it still fails, you installed into a different interpreter than the one running the code, so always use the python -m pip spelling.
The error
ModuleNotFoundError: No module named 'selenium'Fix it
- Install selenium with the running interpreter's pip
python -m pip install seleniumExpected: Successfully installed selenium-....
- Confirm the import
python -c "from selenium import webdriver; print(selenium.__version__ if False else 'ok')"Expected: prints ok. (The version lives at selenium.__version__ if you need it.)
- If it still fails, check for a second Python
python --version
pip --versionExpected: both lines reference the same installation. If not, redo step 1 and skip bare pip.
When this applies
- any
from selenium import ...fails with ModuleNotFoundError naming selenium - a new venv, container, or CI runner
- the script worked on another machine
When it does NOT apply
ImportError: cannot import name 'webdriver' from 'selenium'means a shadowing selenium.py file- chromedriver PATH errors happen after the import succeeds
Compatibility
selenium 4.x current. Needs Python 3.8+. pip install selenium on Python 2 installs the ancient 3.141 line, which is not what you want.
Why it happens
The package was never installed into the active environment, or it was installed into a different Python. This bites hardest with IDE-managed interpreters and with pip vs pip3 pointing at different installations.
Edge cases
- On Debian/Ubuntu, never
apt install python3-seleniumandpip install seleniumin the same env. Pick one package manager. - If your project pins selenium in requirements.txt, install the file (
pip install -r requirements.txt) rather than the bare package so versions stay consistent.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.