chitzui chitzui - 2 years ago 186
Python Question

Fail to run a selenium app in terminal (ImportError: No module named selenium)

I’m new to python and selenium but:
So when I run my python script with the python IDLE (hitting F5), selenium works fine (opens firefox, go to website, do stuff)

but when I try to run my script with the Terminal on OSX (python it fails with following error:

Traceback (most recent call last):
File "", line 3, in <module>
from selenium import webdriver
ImportError: No module named selenium

However, selenium is installed.
When I do run
sudo pip3 install selenium
I get
Requirement already satisfied (use --upgrade to upgrade)

What is wrong here? Thanks

EDIT: as PhJu pointed out: the IDLE used Python3 and my command prompt Python2 – It was a quickfix to have the command prompt use python3

Answer Source

I think you have two different python versions installed so your IDLE uses Python3 and your command prompt runs Python2. To see the current version and the path of the instance of python run the follwing:

import sys

Finally you could uninstall the version you don't need or manually change the PATH environment variable.

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