Python Selenium import error
I am trying to execute some python project and I am getting following error:-
File "feed.py", line 17, in <module>
from selenium import webdriver
ImportError: No module named selenium
I installed selenium package by using pip command for both python2 and python3. If I run python on terminal, I don't get this error if I try to import selenium.
But project I am executing using venv. I am unable to figure out from where it is trying to look for selenium package.
When I execute python2.7/python/python on terminal and run
from selenium import webdriver
, I don't see any import errors. But the project when I execute is giving me error. I am unable to locate the path which is being looked up for selenium. How can I find it?
You may like to create a virtual environment for Selenium, which is okay, so, do as mentioned earlier. But I think the following is needed to install Selenium with Python on Ubuntu.
Since you are on Python2, so install Selenium like this:
sudo apt-get install python-selenium # for Python2
And, if you want to move to Python3, then replace python-selenium with python3-selenium in the above command. Also, do remember to download Geckodriver for Firefox to further work with Selenium.
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.20.1-linux64.tar.gz
You would then need to extract the Geckodriver to a folder such as ~/.local/bin for setting it on your execution PATH.