Giulio Colleluori Giulio Colleluori - 2 years ago 3432
Python Question

ImportError: No module named 'selenium'

I'm trying to write a script to check a website. It's the first time I'm using selenium. I'm trying to run the script on a OSX system. Although I checked in /Library/Python/2.7/site-packages and selenium-2.46.0-py2.7.egg is present, when I run the script it keeps telling me that there is no selenium module to import.

This is the log that I get when I run my code:

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

If you could please let me know if you have any idea of what could be causing the issue that'd be greatly appreciated.

Thank you.

Answer Source

If you have pip installed you can install selenium like so.

pip install selenium

or depending on your permissions:

sudo pip install selenium

As you can see from this question pip vs easy_install pip is a more reliable package installer as it was built to improve easy_install.

I would also suggest that when creating new projects you do so in virtual environments, even a simple selenium project. You can read more about virtual environments here. In fact pip is included out of the box with virtualenv!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download