I want to install selenium webdriver in my Ubuntu 16.04 system for python

When I install Selenium I get the following error:

Shubham@Shubham-To-be-filled-by-O-E-M:~$ sudo apt-get update
    Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
    Hit:2 https://repo.skype.com/deb stable InRelease                       
    Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease                     
    Get:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
    Get:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]  
    Fetched 323 kB in 8s (38.6 kB/s)                                               
    Reading package lists... Done
    Shubham@Shubham-To-be-filled-by-O-E-M:~$ sudo pip install selenium
    Traceback (most recent call last):
      File "/usr/bin/pip", line 9, in <module>
        from pip import main
    ImportError: cannot import name main

How should I proceed?


Solution 1:

Selenium is available from the default Ubuntu repositories in Ubuntu 16.04 and later. To install selenium open the terminal and type:

sudo apt install python-selenium # for Python 2.x

and/or

sudo apt install python3-selenium # for Python 3.x  

Then type python to start the Python interpreter and from selenium import webdriver should work like this:

$ python  
>>> from selenium import webdriver

Assuming that the path ~/.local/bin is in your execution PATH, here's how to install the Firefox webdriver, called geckodriver:

wget https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.20.1-linux64.tar.gz
tar xvfz geckodriver-v0.20.1-linux64.tar.gz
mv geckodriver ~/.local/bin

Solution 2:

To install a specific version go to pypi.

Find a version you need from the Release history and on the example of tag 4.0.0.a7 run:

pip install selenium==4.0.0.a7

enter image description here

The same works for Ubuntu 20.04.