Unable to run selenium on Jupyter Notebook (MasOS, Catalina)

I am unable to run selenium on Jupyter notebook, where Anaconda is my python distribution platform. However, I am able to run selenium using the Python IDLE Shell 3.9.1 and use the Chromedriver in this shell.

This is what shows in jupyter notebook:
! pip3 install selenium

Requirement already satisfied: selenium in /usr/local/lib/python3.9/site-packages (3.141.0)
Requirement already satisfied: urllib3 in /usr/local/lib/python3.9/site-packages (from selenium) (1.26.4)

Then when I execute this command, I received an error that selenium is not a module.

import time
from selenium import webdriver

ModuleNotFoundError Traceback (most recent call last)
1 import time
----> 2 from selenium import webdriver

ModuleNotFoundError: No module named ‘selenium’

Please assit and thank you.

Have you tried the following in a cell in the Jupyter notebook in place of your outdated installation command:

%pip install selenium

It is best in a notebook to use the %pip install and %conda install so that installations happen in the correct environments that the notebook uses. See the very bottom of this reply for a link to related information on those new magic commands that make life much easier. Adding the exclamation point sends it out to a shell which looks in your case to be using your Mac Python and not the Anaconda installed environemnt, it seems.


Again you have come with simple amazing solution to my problem. That absolutely fixed my problem. Thank you again!

1 Like