Thursday, April 16, 2020

Jupyter error - No module named ‘selenium’

Recently I installed Anaconda to learn more about it and the first thing I was about to try was opening a web page automatically using Selenium.

So, to perform this, I used Jupyter and tried to import Selenium webdriver. Till here, everything went well, but when I ran my code using Jupyter Notebook, I got an error: ‘No module named ‘selenium’.

The strange thing is, I got an error, although I have got Selenium installed on my machine using pip with below command: 

pip install selenium.

Now what could be the reason?

So, to analyze it further, I wrote the same Python code in Visual Studio and ran it. It worked perfectly alright.

So, I just thought to give a try to check the version of Selenium and first I tried with pip as shown below:

As the above message says, it is already installed and didn’t complain anything. So, next I thought to try with Anaconda command prompt as shown below: 





















Did you notice that rectangle marked with orange? 

Yes, that was the culprit who was not allowing my code to work. There was a difference in versions and as Jupyter was launched from Anaconda, it was not able to get the correct version.

Once above code ran, I was successfully able to run my below code:







Hope this trick will save you hours.

No comments:

Post a Comment