Giulio Colleluori Giulio Colleluori - 7 months ago 773
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/Class_Checker.py", 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

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!

Comments