Solving Selenium webdriver ImportError: No module named ‘selenium’ in Python

Selenium webdriver ImportError: No module named ‘selenium’ in Python is an error which happens when the selenium directory cannot be found.

In this article I am going to explain what happens when you get this error and how you can solve it with a main solution, we will also explore other solutions which can possibly solve the issue.

Explaining the Error : Selenium webdriver ImportError: No module named ‘selenium’ in Python

This is an error which happens when the selenium directory cannot be found.

The error message should look like the error in the example bellow, make sure you have the same error message in order to avoid confusion.

                                                                       #
Traceback (most recent call last):
  File "/Users/GiulioColleluori/Desktop/Class_Checker.py", line 10, in <module>
    from selenium import webdriver
ImportError: No module named 'selenium'
                                                                       #

Bellow I will present multiple solutions some have worked for me and others have worked for other developers.

Solution 1 : install Selenium in the same directory where Python is installed

This solution includes two options. In both options we assume that Selenium has been installed.

The first option is to install selenium in the same directory as the version of Python you’re using

If that is not the case, then the error will happen. For example, you have installed Selenium to

                                                                       #
/Library/Python/3.5/site-packages
                                                                       #

Then you upgraded python to python 3.7 which is installed in an other directory

                                                                       #
/Library/Python/3.5/site-packages
                                                                       #

The second option is to change the interpreter to match the directory where Selenium is installed.

You can do that in VS Code at the bottom left of your screen.

The solutions above should be enough to solve the problem, Try the next solution if that is not the case.

Solution 2 : install selenium using pip or pip3

The second solution is for people who do not have Selenium at all or those who want to re-install Selenium.

You can always use pip if pip works for you

                                                                       #
pip install selenium
# or use sudo
sudo pip install selenium
                                                                       #

You should try pip3 if you have python3

                                                                       #
sudo pip3 install selenium
                                                                       #

Try the last solution bellow if the solutions above failed.

Solution 3 : install webdriver_manager

Sometimes, the easiest fix to this problem for some people is to install webdriver_manager.

You can do that easily by using pip

                                                                       #
pip install webdriver_manager
                                                                       #

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up

This article is over guys, You can support us by donating to our Kofi account, you can find a red button at the top of this page. Good luck with your Python journey, keep coding, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/