chitzui chitzui - 6 months ago 56
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 app.py) it fails with following error:

Traceback (most recent call last):
File "app.py", 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

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
sys.version
sys.path

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

Comments