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.

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