Python provides various modules that help users to automate their daily tasks. One such module, named “selenium,” is used in Python to automate the web browser or web applications. To access the “selenium” module in Python, we need to import it at the program’s start. The error “no module named selenium” appeared when the user imported the module without being installed in Python.
This write-up will provide reasons and possible solutions to rectify the “no module named selenium” error. The given below concepts will be explained in this article:
- Reason: ‘selenium’ Module is Not Installed in Python
- Solution (For Windows): Install the Python ‘selenium’ Module
- Solution (For Linux): Install the Python ‘selenium’ Module
So, let’s get started!
Reason: ‘selenium’ Module is Not Installed in Python
The main reason which causes this error in Python is when the “selenium” module is imported into the program without being installed in Python. The below snippet shows the error:
The above output shows a “no module named selenium” error because the selenium module was not installed in Python.
Solution (For Windows): Install the Python ‘selenium’ Module
To fix this error in Python, we need to install the selenium module using the “pip” package manager command. If you don’t have pip, then you can follow this guide.
Step 1: Launch Command Prompt Terminal
To install the selenium module, you need to open the “cmd” terminal window by following the below snippet or pressing the window key button along with “R”.
Step 2: Install selenium Module Using pip
After opening cmd, type the below-given pip command to install the “selenium” module in Python:
pip install selenium
Alternatively, you can use the below command for installation of “selenium” module:
pip3 install selenium
The above snippet verified that the “selenium” module has been downloaded and installed in Python.
If a permission error arises while executing the above command. In that case, you can use the following command in the terminal:
pip install selenium --user
Step 3: Verification of selenium Module
After installing the Python selenium module, we can verify it by executing the following command in the terminal:
pip show selenium
The above snippet shows the version and all details of the “selenium” module that was installed in Python.
Install selenium Module in Anaconda
To install the selenium module in the anaconda environment, you can use the given below command:
conda install -c conda-forge selenium
Install selenium Module in Jupyter Notebook
To install this module in Jupyter Notebook you can use the following command:
!pip install selenium
Solution (For Linux): Install the Python ‘selenium’ Module
To install the selenium module in Python you can use the “pip” package manager command in Linux. If you don’t have a pip, you can install it by checking this installation guide.
After installation of “pip”, you can use the given below command to install the selenium module in your Python:
$ sudo pip install selenium
There is another alternative option to install the “selenium” module in Python, i.e., using the “apt” command. Before installing the module, we need to update the “repository” using the given below command:
$ sudo apt update
After updating the repository now install the “selenium” module using the given below command:
$ sudo apt -y install python3-selenium
Alternate Reasons Invoke “ModuleNotFoundError: No module named ‘selenium’”
This error also arises in a program when we installed the package globally in our system but forgot to install it in a virtual environment. Another reason is that we install it correctly in cmd, but our Python IDE runs an incorrect version of Python. In our scenario, we are using a “thorny” IDE in the virtual environment that is not connected to the globally installed version of Python. To solve this, we need either to select the version that is installed in our system or install the module in the editor shell manager.
That’s it from this guide!
Conclusion
The “no module named selenium” error occurs when we try to import the “selenium” module without installing it in Python. To resolve this error in Windows and Linux, you need to install the “selenium” module using the “pip” and “apt” commands. This article presented various reasons and respective solutions to rectify the “no module named selenium” error in Python.