How to Fix 'chromedriver' Executable Needs to Be in PATH Error in Selenium: A Beginner's Guide for PyCharm Users

If you’re new to Selenium and PyCharm, you’ve likely encountered the frustrating error: “‘chromedriver’ executable needs to be in PATH”. This error occurs when Selenium can’t locate the chromedriver executable, a critical component that allows Selenium to control the Chrome browser.

As a beginner, navigating PATH variables, driver versions, and file paths can feel overwhelming. But fear not! This guide will break down the error, explain why it happens, and walk you through 5 simple methods to fix it—tailored specifically for PyCharm users. By the end, you’ll be running Selenium scripts smoothly.

Table of Contents#

  1. Understanding the Error
    • What is the “chromedriver in PATH” error?
    • Why does it occur?
  2. Prerequisites
  3. Step-by-Step Solutions
  4. Troubleshooting Common Issues
  5. Conclusion
  6. References

Understanding the Error#

What is the “chromedriver in PATH” Error?#

Selenium WebDriver requires a browser-specific driver (e.g., chromedriver for Chrome, geckodriver for Firefox) to interact with the browser. The error “‘chromedriver’ executable needs to be in PATH” means Selenium cannot find chromedriver in your system’s PATH environment variable—a list of directories your operating system searches for executable files.

Why Does It Occur?#

Common causes include:

  • chromedriver is not installed on your system.
  • chromedriver is installed but not added to your system’s PATH.
  • The installed chromedriver version does not match your Chrome browser version.
  • You’re using an outdated Selenium version with deprecated syntax.

Prerequisites#

Before proceeding, ensure you have:

  • Google Chrome installed (check version via chrome://settings/help).
  • PyCharm (Community or Professional Edition) installed.
  • Python (3.6+) and pip (Python package manager) installed (verify with python --version and pip --version in PyCharm’s terminal).

Step-by-Step Solutions#

Method 1: Check Chrome and Chromedriver Installation#

First, confirm you have Chrome and chromedriver installed (and that their versions match).

Step 1: Check Your Chrome Version#

  1. Open Chrome.
  2. Go to chrome://settings/help (or click Menu → Help → About Google Chrome).
  3. Note your Chrome version (e.g., 119.0.6045.160).

Step 2: Download the Matching Chromedriver#

  1. Go to the official Chromedriver download page.
  2. Click the link matching your Chrome version (e.g., 119.0.6045.105).
  3. Download the appropriate version for your OS (Windows, macOS, or Linux).
  4. Extract the ZIP file to a folder (e.g., C:\chromedriver on Windows, ~/chromedriver on macOS/Linux).

Method 2: Add Chromedriver to System PATH#

Adding chromedriver to your system’s PATH lets your OS (and PyCharm) find it automatically.

For Windows Users:#

  1. Locate your chromedriver.exe file (e.g., C:\chromedriver\chromedriver.exe).
  2. Copy the folder path (e.g., C:\chromedriver).
  3. Open System Properties:
    • Press Win + R, type sysdm.cpl, and hit Enter.
    • Go to the Advanced tab → Environment Variables.
  4. Under “System Variables,” scroll to Path and click Edit.
  5. Click New and paste the folder path (e.g., C:\chromedriver).
  6. Click OK to save changes.

For macOS/Linux Users:#

  1. Locate your chromedriver file (e.g., ~/chromedriver/chromedriver).
  2. Open Terminal (in PyCharm: View → Tool Windows → Terminal).
  3. Edit your shell config file (e.g., ~/.bashrc, ~/.zshrc, or ~/.profile):
    nano ~/.zshrc  # For Zsh (default on macOS)  
    # OR  
    nano ~/.bashrc  # For Bash  
  4. Add this line at the end (replace ~/chromedriver with your folder path):
    export PATH="$PATH:/Users/yourusername/chromedriver"  
  5. Save and exit: Press Ctrl + O, Enter, then Ctrl + X.
  6. Refresh the terminal:
    source ~/.zshrc  # Or source ~/.bashrc  

Verify PATH Update#

In PyCharm’s terminal, run:

chromedriver --version  

If you see the version (e.g., ChromeDriver 119.0.6045.105), the PATH is set correctly!

Method 3: Specify Chromedriver Path Directly in Code#

If adding to PATH feels complex, hardcode the chromedriver path in your Selenium script.

For Selenium 3.x (Older Versions):#

from selenium import webdriver  
 
# Replace with your chromedriver path  
driver = webdriver.Chrome(executable_path="C:/chromedriver/chromedriver.exe")  # Windows  
# OR  
driver = webdriver.Chrome(executable_path="/Users/yourusername/chromedriver/chromedriver")  # macOS/Linux  
 
driver.get("https://www.google.com")  
driver.quit()  

For Selenium 4.x (Newer Versions):#

The executable_path argument is deprecated. Use the Service class instead:

from selenium import webdriver  
from selenium.webdriver.chrome.service import Service  
 
# Replace with your chromedriver path  
service = Service("C:/chromedriver/chromedriver.exe")  # Windows  
# OR  
service = Service("/Users/yourusername/chromedriver/chromedriver")  # macOS/Linux  
 
driver = webdriver.Chrome(service=service)  
driver.get("https://www.google.com")  
driver.quit()  

The easiest fix for beginners! Webdriver Manager automatically downloads, manages, and updates chromedriver for you—no manual PATH setup required.

Step 1: Install Webdriver Manager#

In PyCharm’s terminal, run:

pip install webdriver-manager  

Step 2: Use It in Your Script#

from selenium import webdriver  
from selenium.webdriver.chrome.service import Service  
from webdriver_manager.chrome import ChromeDriverManager  
 
# Automatically install and use the latest chromedriver  
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))  
 
driver.get("https://www.google.com")  
print("Page title:", driver.title)  # Should print "Google"  
driver.quit()  

Why this works: ChromeDriverManager().install() downloads the correct chromedriver version and tells Selenium where to find it.

Method 5: Verify the Fix in PyCharm#

To confirm the error is resolved:

  1. Create a new PyCharm project (File → New Project).
  2. Create a Python file (e.g., test_selenium.py).
  3. Paste the Webdriver Manager script from Method 4.
  4. Run the script (right-click → Run ‘test_selenium’).

If Chrome opens, navigates to Google, and prints the title, the error is fixed!

Troubleshooting Common Issues#

1. Version Mismatch#

Error: This version of ChromeDriver only supports Chrome version X.
Fix: Ensure chromedriver version matches Chrome (Method 1). Use Webdriver Manager (Method 4) to auto-resolve.

2. Permission Errors (macOS/Linux)#

Error: Permission denied: 'chromedriver'.
Fix: In Terminal, run:

chmod +x /path/to/chromedriver  # Makes chromedriver executable  

3. PATH Not Updating#

Error: chromedriver: command not found after adding to PATH.
Fix: Restart PyCharm and your terminal. On Windows, log out and back in.

4. 32-bit vs 64-bit#

Error: Bad CPU type in executable (macOS) or not a valid Win32 application (Windows).
Fix: Download the correct architecture (64-bit recommended) from the Chromedriver page.

Conclusion#

The “chromedriver in PATH” error is a common hurdle, but it’s easily fixed! For beginners, Webdriver Manager (Method 4) is the simplest and most reliable solution—it eliminates manual downloads and PATH setup. If you prefer manual control, adding chromedriver to PATH (Method 2) or hardcoding the path (Method 3) works too.

With these steps, you’ll be automating Chrome with Selenium in PyCharm in no time!

References#