Modulenotfounderror: no module named ‘selenium’

In this tutorial, you will learn the solutions on how to solve the modulenotfounderror: no module named selenium.

What is Selenium?

Selenium is an open-source, automated testing framework which is used to automate web browsers.

It allows the developers and testers to write scripts in different programming languages (like Java, Python, C#, etc.).

This is to replicate the user actions on a website, like clicking links, filling out forms, and navigating between pages.

A selenium also provides a compatible of tools for testing web applications across different browsers and operating systems.

Furthermore, the selenium is generally used in the software industry for testing web applications.

Securing their functionality, performance, and reliability.

It is also used for web scraping and data extraction tasks.

What is modulenotfounderror?

The ModuleNotFoundError is a Python inbuilt exception which is occurred if a module cannot be found during the import process.

This error occurs if the python interpreter cannot locate the module name that you are trying to import.

What are the causes of error no module named ‘selenium’?

Here are the multiple reasons why modulenotfounderror: no module named selenium may occur:

  • The module name selenium is misspelled or the spelling name is wrong.
  • The module is haven’t been installed or it is not been installed in the current path environment.
  • The module is located in a different directory than the one specified in the PYTHONPATH environment variable
  • There is a conflict between modules with the same name.

Why the error modulenotfounderror no module named selenium occur?

The error modulenotfounderror no module named selenium occurs because the python interpreter cannot find the installed module ‘selenium’ on your system.

Alternatively, you have installed different versions of python on your system.

The module ‘selenium’ is haven’t been installed in the correct PYTHONPATH environment.

Furthermore, the no module named selenium occurs if the python interpreter is cannot find the module Selenium during the import process.

How to solved the modulenotfounderror: no module named selenium?

Time needed: 3 minutes

Here are the solutions to solve the modulenotfounderror no module named ‘selenium’ in a different platform.

  • Solution 1: Installed Selenium Module in Windows

    In your project folder root directory.

    Open a command prompt or terminal windows to install the selenium module in your windows.

    The following command to install:

    pip install selenium

    After you run the command above, the result will install the selenium packages.

    install selenium for Modulenotfounderror no module named 'selenium'

    Install selenium module in Python 3:

    pip3 install selenium

    After you run the command above, the result will install the selenium packages in your python 3.

    install selenium in python3 for Modulenotfounderror no module named 'selenium'

    Install selenium module in server-user:
    If you get an error in server side type this command to install the install selenium module in server-user.

    pip install selenium --user

    After you run the command above, the result will install the selenium packages in your server side.
    install selenium in server side for Modulenotfounderror no module named 'selenium'

    Install pip in your Path Environment Variable
    if you don’t have pip in your PATH environment variable in your windows.

    This is the following command to install pip with selenium module:

    python -m pip install selenium

    After you run the command above, the result will install the pip with selenium packages.

    install pip selenium Modulenotfounderror no module named 'selenium'

    Install pip in your Path Environment Variable in Python 3
    If you don’t have pip in your PATH environment variable in your python 3.

    This is the following command to install pip with selenium module:

    python3 -m pip install selenium

  • Solution 2: Installed Selenium Module in py alias

    In your project folder root directory.

    Open a command prompt or terminal windows to install the selenium module in your py alias.

    The following command to install:

    py -m pip install selenium

    After you run the command above, the result will install the selenium packages in your py alias.

    install selenium in py alias for Modulenotfounderror no module named 'selenium'

  • Solution 3: Installed Selenium Module in Jupyter Notebook

    The following command to install the selenium module on Jupyter Notebook

    !pip install selenium

    After you run the command above, the result will install the selenium packages in your jupyter notebook.

    install selenium in jupyter notebook for Modulenotfounderror no module named 'selenium'

  • Solution 4: Installed Selenium Module in Ubuntu

    The following command to install the selenium module on Ubuntu

    sudo apt install selenium

What is the difference Between ImportError and ModuleNotFoundError?

The difference between ImportError and ModuleNotFoundError is that the ImportError is a general exception that is occurred when an import statement fails for any reason.

Meanwhile, the ModuleNotFoundError is the common exception that was introduced in Python 3.6.

It occurs if an import statement fails because the specified module cannot find in any of the locations.

Where Python searches for modules. For example, the directories recorded in the sys.path variable.

Check if the module selenium is installed

You can check if you have installed the selenium module by executing the command:

pip show selenium

After you run the above command, it shows the package is not installed.

It will show information about the package, including the name, version, license, and the location where the package is installed.

Frequently Asked Questions

What is Python ModuleNotFoundError and what causes it?

ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn’t installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can’t find your local module on the import path. The error message names exactly which module is missing.

How do I fix ‘ModuleNotFoundError: No module named X’?

Run pip install X first. If that succeeds but you still get the error, check which Python you’re using (which python OR python –version) vs which pip (which pip OR pip –version), they must match. Common gotcha: pip points to system Python 3.9 but you’re running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.

Why does my code work in one environment but not another?

Different Python versions or different installed packages. To diagnose: pip freeze > requirements.txt on the working environment, then pip install -r requirements.txt on the broken one. Use virtualenv (python -m venv venv) or conda for every project to avoid system-wide package collisions.

Is ModuleNotFoundError the same as ImportError?

ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means ‘no such module exists.’ Plain ImportError covers a wider set: module exists but a name inside it can’t be imported (e.g. ‘cannot import name X from Y’). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.

Where can I find more ModuleNotFoundError fixes?

Browse the ModuleNotFoundError reference hub for 198+ specific module fixes (TensorFlow, Flask, Django, pandas, numpy, etc.). For related issues see ImportError. For broader Python setup see Python Tutorial hub.

Conclusion

In conclusion, I hope the solutions above can help you to solve the error Modulenotfounderror: no module named ‘selenium’ you encountered in different platforms.

Leave a Comment