How to Install Selenium in Python
What you’ll build or solve
You’ll install Selenium into the Python environment you actually run and confirm Python can import it.
When this approach works best
Installing Selenium works best when you want to:
Learn Python on Mimo
- Automate a browser for testing a web app, like clicking buttons and filling forms.
- Scrape pages that require JavaScript to render content.
- Reproduce a manual workflow in a controlled script, like checking a dashboard and downloading a report.
This is a bad idea when a simple HTTP request is enough. If the page returns the data without a browser, use Requests instead.
Prerequisites
- Python 3 installed
- Access to a terminal (Command Prompt, PowerShell, or a macOS/Linux terminal)
Step-by-step instructions
1) Install Selenium with pip
Use python -m pip so pip matches the Python you plan to run.
Option A: Install Selenium (most common)
python-m pip install selenium
Option B: If your system uses python3
python3-m pip install selenium
Option C: Install a specific version
python-m pip install"selenium==4.18.1"
What to look for: If you see “Requirement already satisfied,” Selenium is already installed in that environment.
2) Confirm the install worked
Import Selenium and print its version.
python-c"import selenium; print(selenium.__version__)"
What to look for:
ModuleNotFoundError: No module named 'selenium' usually means you installed Selenium for a different Python version than the one you are running.
3) Confirm your browser driver setup works
Modern Selenium can often manage drivers for you, but you still want a quick sanity check by launching a browser.
fromseleniumimportwebdriver
driver=webdriver.Chrome()
driver.get("https://example.com")
print(driver.title)
driver.quit()
What to look for: If the browser opens and closes without errors, your setup is working. If you see a message about a missing driver or version mismatch, jump to Troubleshooting.
Examples you can copy
Example 1: Install and verify in one go
python-m pip install selenium
python-c"import selenium; print(selenium.__version__)"
Example 2: Verify which Python and pip you are using
python-c"import sys; print(sys.executable)"
python-m pip--version
Example 3: Quick Chrome launch test
fromseleniumimportwebdriver
driver=webdriver.Chrome()
driver.get("https://example.com")
print(driver.current_url)
driver.quit()
Example 4: Use Firefox instead of Chrome
fromseleniumimportwebdriver
driver=webdriver.Firefox()
driver.get("https://example.com")
print(driver.title)
driver.quit()
Example 5: Install in an already activated virtual environment
python-m pip install selenium
python-c"import selenium; print(selenium.__version__)"
python-c"import sys; print(sys.executable)"
Common mistakes and how to fix them
Mistake 1: Installing Selenium, then importing in a different Python environment
What you might do
python-m pip install selenium
python3-c"import selenium"
Why it breaks
You installed into one interpreter, then ran another.
Corrected approach
Use the same command for both install and import.
python3-m pip install selenium
python3-c"import selenium; print(selenium.__version__)"
Mistake 2: Mixing browser and driver versions
What you might do
- Install Selenium
- Run
webdriver.Chrome()and get a driver error
Why it breaks
The driver may be missing, blocked, or not compatible with your browser version.
Corrected approach
Update your browser, then try again. If your environment blocks automatic driver management, install the driver through your system package manager or provide a driver path in your script.
Troubleshooting
If you see ModuleNotFoundError: No module named 'selenium', do this:
python-c"import sys; print(sys.executable)"
python-m pip install selenium
Make sure you install Selenium with the same interpreter you run.
If you see selenium.common.exceptions.WebDriverException about a driver, update your browser first. Then retry the simple launch test. Corporate machines sometimes block driver downloads.
If Chrome opens and instantly closes with an error, run the test again and read the full stack trace. Many issues come from a mismatched Chrome/ChromeDriver pair.
If you are on Windows and python opens the Store, use the launcher:
py-m pip install selenium
py-c"import selenium; print(selenium.__version__)"
If you get permission errors installing packages, install in a virtual environment or use a user install:
CSS
python-m pip install--user selenium
Quick recap
- Install with
python -m pip install selenium - Verify with
python -c "import selenium; print(selenium.__version__)" - Run a quick browser launch test with
webdriver.Chrome()orwebdriver.Firefox() - If imports fail, check
sys.executableto confirm which Python you are running
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot