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?

  • Did you install it systemwide or did you install it in the venv? You have to enter your venv and THEN install it with pip so it installs in the venv. Unless configured right at the time of the creation, the venv won't inherit the system modules store. – Thomas Ward Sep 16 '19 at 15:51
  • Initially i installed system wide and not in venv.Now i am trying to install in venv but it says package is already there.Please see my comment below the answer – BATEESH Sep 17 '19 at 9:23

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.

| improve this answer | |

First activate the virtual environment:

$ source venv/bin/activate

... tthen your terminal will look like this:


Then install selenium:

(venv) $ pip install selenium

Then you will have selenium installed inside the venv.

The next time when you open a new terminal, just activate the venv and run your code.

| improve this answer | |
  • I start running a script which has a statement "source venv/bin/activate".Now as you have mentioned,I ran source venv/bin/activate in a new terminal and then i got message as follow. – BATEESH Sep 17 '19 at 9:22
  • Collecting selenium Using cached files.pythonhosted.org/packages/80/d6/… Requirement already satisfied: urllib3 in ./venv/lib/python2.7/site-packages (from selenium) (1.24.2) Installing collected packages: selenium Successfully installed selenium-3.141.0 – BATEESH Sep 17 '19 at 9:22
  • @BATEESH is your venv Python 2 or Python 3? – Thomas Ward Sep 17 '19 at 14:25
  • When i run pyhton-v in venv,it shows following.python -V Python 2.7.15rc1 – BATEESH Sep 20 '19 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.