Fixing ModuleNotFoundError: No module named ‘Selenium’

Step-by-step guide to resolve the "ModuleNotFoundError: No module named 'Selenium'" and troubleshoot installation problems effectively.

Written by Rushabh Shroff Rushabh Shroff
Reviewed by Bhumika Babbar Bhumika Babbar
Last updated: 4 August 2026 12 min read

Key Takeaways

  • A built-in Python exception meaning the active interpreter can't find Selenium in its sys.path, not a Selenium-specific bug.
  • Reinstall Selenium against the correct interpreter or activate the right virtual environment, then verify with the checklist.
  • Use dedicated virtual environments, pin dependencies in requirements.txt, and test consistently across browsers/CI runners (e.g., BrowserStack Automate).

If you’re testing your web application using Selenium but get a “ModuleNotFoundError”, it means Python couldn’t find the Selenium package in the environment running your script.

This usually happens because the package is missing, installed in the wrong environment, or the environment itself wasn’t activated properly.

Left unresolved, this halts your script at the very first line and can block CI/CD pipelines outright, turning a single missing package into a wider test collaboration problem.

This guide walks through root causes of the error and how to verify pip, installation and interpreter path.

What is a ModuleNotFoundError in Selenium?

ModuleNotFoundError is a built-in Python exception, raised whenever an import statement can’t locate the module it’s asking for. In this case, Python is looking for Selenium and coming up empty, so it stops execution right there.

It’s not a Selenium-specific error; it’s a standard Python error that happens to be pointing at Selenium. The exception itself doesn’t say why the module is missing.

What Causes the ModuleNotFoundError: No module named ‘Selenium’ Error?

Sometimes, Python cannot locate the Selenium package in your environment due to the tester’s own miss.

Every time you import Selenium, Python only checks one list, i.e., sys.path, that points to packages in the active test environment. Narrow mechanical errors include:

1. Selenium was never installed in this environment

The most literal cause: nobody ran `pip install selenium here. Confirm with:

bash

pip show selenium

Selenium was never installed in this environment

No output means it’s not installed in whichever environment pip currently points to.

2. Multiple Python versions, wrong one in use

If your machine has more than one Python installed (very common with pyenv, Homebrew, or a system Python alongside a manually installed one), Selenium might be sitting in one and your script running in another.

bash

python3 --version

pip3 --version

Multiple Python versions wrong one in use

If the paths or versions look mismatched, install explicitly against the interpreter you intend to use:

bash

python3 -m pip install selenium

3. Virtual environment exists but isn’t activated

Say a virtual environment (venv) was created and Selenium was installed inside it.

But the terminal running the script never activated it, so Python quietly falls back to the global interpreter, which has nothing installed.

bash

# macOS/Linux

source venv/bin/activate



# Windows

venv\Scripts\activate

Only after activation should you run pip install selenium or your test script.

4. Incomplete or Corrupted Installation

Interrupted installs (network drop, disk space, or permission errors mid-install) can leave a broken package directory. `pip show selenium may return incomplete or odd metadata in this case. The fix is a clean reinstall:

bash

pip uninstall selenium -y

pip install selenium

5. Types in Import Statements

Small, but it happens more than you’d expect, especially with autocomplete or copy-pasted snippets from older tutorials.

python:

# Wrong

import Selenium



# Correct

from selenium import webdriver

Python is case-sensitive, and the module name is lowercase.

6. Outdated pip Version

An old pip can fail to resolve dependencies correctly or silently install them to the wrong location.

bash

python3 -m pip install --upgrade pip

Outdated pip

What’s Actually Happening When You See This Error

Before fixing it, it helps to know what Python is actually doing when it throws this error:

  • Sys.path verification: Python doesn’t search your whole machine for a package called “selenium”; it only checks sys. path, the list of locations tied to the active interpreter.
  • Test environment: “Selenium is installed on my computer” means nothing to Python if it isn’t installed in the exact environment your script is currently running under.
  • Incorrect installation: You can have Selenium installed in three different places on one machine and still hit a ModuleNotFoundError if your script happens to run through a fourth.
  • Interpreter confusion: This is especially common in Selenium WebDriver Python projects, since Python testers often juggle more interpreters: system Python, a Homebrew or pyenv version or one or more virtual environments.

You can confirm which interpreter is actually in play with two quick commands:

bash


# See exactly which Python you're running

python3 -c "import sys; print(sys.executable)"



# See if Selenium is visible to that interpreter

python3 -c "import selenium; print(selenium.__version__)"

confirm which interpreter is actually in play with two quick commands

If the second command fails, that’s your confirmation; Selenium simply isn’t installed where this interpreter is looking.

How to Fix ModuleNotFoundError in Selenium?

You can take several steps to resolve this issue and get back to running your Selenium automation scripts.

Step 1. Install Selenium

If you haven’t installed the Selenium package yet, you need to do so. Without installation, Python cannot recognize or use the library, leading to the error.

Open your terminal or command prompt.

Run the following command:

pip install selenium

This will install the latest version of Selenium in your environment.

Step 2. Check for Multiple Python Versions

If you have multiple Python versions installed, you may have installed Selenium in one version but are using another to run your script. This mismatch can result in the ModuleNotFoundError.

Check your Python version with:

python –version

If you are using Python 3, ensure you use pip3 instead of pip:

pip3 install Selenium

Alternatively, use the –m flag to specify the version of Python:

python3 -m pip install selenium

Step 3. Activate Your Virtual Environment

If you’re using a virtual environment, Selenium must be installed within that environment. If you haven’t activated it, Python won’t be able to find the packages installed in that environment.

Navigate to your project directory and activate the virtual environment.

On Windows:

venv\Scripts\activate

On Mac/Linux:

source venv/bin/activate

Once activated, install Selenium inside the virtual environment:

pip install Selenium

Step 4. Reinstall Selenium

If you’ve already installed Selenium but the error persists, there may be an issue with the installation. Reinstalling the package can help resolve issues caused by corrupt or incomplete installations.

Uninstall Selenium:

pip uninstall Selenium

Reinstall Selenium:

pip install Selenium

Step 5. Check for Types in the Import Statement

A common cause of this error is a typo in the import statement. Ensure that the module name is spelled correctly.

Correct Import Statement:

from selenium import webdriver

Double-check for any misspellings.

Step 6. Ensure Your pip is Up-to-Date.

If your pip is outdated, it may be unable to find or install the required packages properly. Ensure you’re using the latest version of pip to install Selenium.

python3 -m pip install --upgrade pip

Step 7. Verify Selenium Installation

After installation, verify that Selenium is correctly installed by running:

pip show selenium

This will display information about the Selenium package, including its version and installation path. If no information is displayed, it means Selenium has not been installed correctly.

Step 8. Check for Other Python Package Issues

If none of the above steps work, there may be an issue with your overall Python environment or installation. Try creating a new environment or reinstalling Python.

Create a new virtual environment:

python3 -m venv new_env

Activate it and install Selenium:

source new_env/bin/activate  # On Windows: new_env\Scripts\activate

pip install Selenium

Why This Disrupts More Than Just Your Script

It’s easy to treat this as a one-line problem, but for QA teams it needs an immediate fix. Not fixing the import command can potentially stop a test release.

  • Execution stops at import time. Nothing downstream runs; no test cases, no exception handling, nothing. There’s no partial log to debug from, which makes it feel worse than it is.
  • CI/CD pipelines fail as a whole build, not a single test case. If your CI/CD job doesn’t pin dependencies properly, a missing package can block an entire release gate instead of flagging one broken assertion.
  • Intermittent occurrences point to environment drift. If the error shows up only on certain runners, or only on one teammate’s laptop, that’s rarely a Selenium problem; it’s a sign of organisational failure.
  • Debugging time shifts from test logic to environment forensics. Testers end up spending time confirming Python versions and pip paths instead of improving coverage, which is often the real cost nobody accounts for.

Confirming the Fix: A Six-Step Verification Checklist

After implementing the suggested fixes for the ModuleNotFoundError in Selenium, it’s important to test whether the issue has been resolved. Here’s a step-by-step guide to verify that Selenium is correctly installed and ready to use:

Step 1. Verify Selenium Installation

The first step is to confirm that Selenium has been installed in the correct Python environment.

Open your terminal or command prompt.

Run the following command:

pip show selenium

If Selenium is installed correctly, you should see details like the version number and installation path. If nothing shows up, Selenium is not installed, and you’ll need to install it again using pip install selenium.

Step 2. Test a Simple Selenium Script

After verifying that Selenium is installed, running a simple Selenium script is the best way to test the fix. This will confirm that the module can be imported and functions correctly.

Create a new Python script (for example, test_selenium.py).
Add the following code to launch a browser (ensure you have a compatible WebDriver installed, such as ChromeDriver or GeckoDriver for Firefox):

from selenium import webdriver



# Start a new Chrome browser session

driver = webdriver.Chrome()  # or webdriver.Firefox() if using Firefox




# Open a website

driver.get("https://www.example.com")



# Verify the page title

print("Page title is:", driver.title)



# Close the browser

driver.quit()

Expected Output: The browser should launch, navigate to the specified website, print the page title in the terminal, and then close the browser.

If the script runs without any errors, it confirms that Selenium is installed and working correctly.

Step 3. Check for Browser Compatibility

Sometimes, even if Selenium is installed, the browser version may not be compatible with the WebDriver you’re using (for example, ChromeDriver for Google Chrome). Ensure that the version of WebDriver matches the browser version on your machine.

Check the browser version (for example, in Chrome, go to chrome://settings/help).

Download the correct version of the WebDriver from the official source (for example, ChromeDriver downloads).

Step 4. Testing in a Virtual Environment

If you’re using a virtual environment, it’s important to confirm that the environment is properly set up and the necessary packages are installed within it.

Activate your virtual environment:

source venv/bin/activate  # On Windows: venv\Scripts\activate

If the script works, it confirms that Selenium is properly installed in the virtual environment.

Step 5. Check for Typos or Import Issues

Ensure that the import statement in your script is correct.

Step 6. Reinstall Selenium for Persistent Issues

If you encounter repeated problems, uninstall and reinstall Selenium to ensure a clean setup. Download the package manually and unpack it. Then, install the module using the command:

python3 setup.py install

After this, you can import the module in Python 3.

Best Practices to Prevent the ModuleNotFoundError in Selenium

Following a few best practices is essential to minimise the chances of encountering the ModuleNotFoundError in Selenium.

These guidelines ensure your Python environment remains organised, dependencies are managed effectively and Selenium setup functions smoothly.

  • Treat virtual environments as mandatory, not optional. One env per project keeps dependency versions from silently colliding across work.
  • Pin dependencies in a requirements.txt file so “works on my machine” becomes “works wherever this file is installed”:
  • Keep pip current as part of your normal setup routine, not just when something breaks.
  • Match WebDriver versions to installed browser versions. This becomes especially relevant once the import error is resolved and you move on to actually running tests. Selenium 4 largely automates this through Selenium Manager, but it’s worth verifying on older setups.
  • Document your environment setup (Python version, Selenium version, OS) somewhere your team can reference, especially for onboarding.
  • Run your suite regularly, not just before releases, so environment drift gets caught early rather than discovered during a deadline.

Conclusion

By identifying the root cause of the ModuleNotFoundError in Selenium, you can identify what’s holding your script back: interpreter path, environment variable, or incorrect pip download.

Installing correctly, activating your virtual environment, and verifying with pip show selenium resolves the vast majority of cases.

Once your script runs cleanly, the next real test is whether it behaves consistently across browsers, OS versions, and CI runners.

Running your suite on BrowserStack Automate is a straightforward way to confirm that without maintaining your own device and browser infrastructure.

Version History

  1. Jul 30, 2026 Current Version

    Added 3 new sections, edited and removed sections that don’t align with intent of python developers, and edited meta, intro and conclusion for ICP targeting

    Bhumika Babbar
    Reviewed by Bhumika Babbar Principal Engineer
Tags
Automation Testing Selenium Website Testing
Rushabh Shroff
Rushabh Shroff

Lead - Software Development Engineer

Rushabh Shroff is a Test Automation and Quality Engineering leader with 5+ years of experience helping teams build scalable, reliable testing strategies. He specializes in test automation, AI-assisted QA, and enterprise software quality, enabling faster and more confident releases.

FAQs

Pin your dependencies in requirements.txt and make sure your pipeline’s install step runs against the same Python version your tests expect. Environment drift between local and CI setups is the most common cause of “It works on my machine, but not in the pipeline.”

That’s expected. A resolved ModuleNotFoundError just means Python can’t find the package. A subsequent error, like a driver mismatch, is a separate issue. Common next ones are SessionNotCreatedException and general WebDriver exceptions.

Not strictly, but it’s strongly recommended. It isolates your project’s dependencies so a version conflict in one project can’t silently break another, and it’s the single most common source of this exact error.

On many systems they point to the same thing, but not always, especially on machines with multiple Python versions. Using ‘python3 -m pip install selenium’ is the safest option since it ties the install directly to the interpreter you’re about to run it with.

Almost always an environment mismatch. Selenium was installed into a different Python interpreter or virtual environment than the one currently running your script. Confirm with python3 -c “import sys; print(sys.executable)” and reinstall against that exact path.

Automation Tests on Real Devices & Browsers
Seamlessly Run Automation Tests on 3500+ real Devices & Browsers