How to Install Selenium for Python on Windows or Linux

Windows

# This error would occur if pip is not up to date
PS C:\WINDOWS\system32> pip install selenium
Collecting selenium
  Downloading https://files.pythonhosted.org/packages/ad/24/39cab5fbaf425ff522e1e51cce79f94f10f9523f015d2b2251e43f45e8a2/selenium-4.0.0-py3-none-any.whl (954kB)
     |████████████████████████████████| 962kB ...
~ Truncated ~
Building wheels for collected packages: cryptography
  Building wheel for cryptography (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\python38\python.exe' 'c:\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\DRAGON~1\AppData\Local\Temp\tmprcrddpd1'
~ Truncated ~
  If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.

  This package requires Rust >=1.41.0.

      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation/ for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq/
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation/#rust

      Python: 3.8.0
      platform: Windows-10-10.0.19041-SP0
      pip: n/a
      setuptools: 58.2.0
      setuptools_rust: 0.12.1
      =============================DEBUG ASSISTANCE=============================

  ----------------------------------------
  ERROR: Failed cleaning build dir for cryptography
Failed to build cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly
Failed to build cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 19.2.3, however version 21.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

# upgrade pip
PS C:\WINDOWS\system32> python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/90/a9/1ea3a69a51dcc679724e3512fc2aa1668999eed59976f749134eb02229c8/pip-21.3-py3-none-any.whl (1.7MB)
     |████████████████████████████████| 1.7MB 6.4MB/s
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
Successfully installed pip-21.3

# Successful installation of selenium
PS C:\WINDOWS\system32> pip install selenium
Collecting selenium
  Using cached selenium-4.0.0-py3-none-any.whl (954 kB)
Collecting trio-websocket~=0.9
  Using cached trio_websocket-0.9.2-py3-none-any.whl (16 kB)
Collecting trio~=0.17
  Using cached trio-0.19.0-py3-none-any.whl (356 kB)
Collecting urllib3[secure]~=1.26
  Using cached urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
Collecting cffi>=1.14
  Using cached cffi-1.15.0-cp38-cp38-win_amd64.whl (179 kB)
Collecting idna
  Using cached idna-3.3-py3-none-any.whl (61 kB)
Collecting async-generator>=1.9
  Using cached async_generator-1.10-py3-none-any.whl (18 kB)
Collecting outcome
  Using cached outcome-1.1.0-py2.py3-none-any.whl (9.7 kB)
Collecting attrs>=19.2.0
  Using cached attrs-21.2.0-py2.py3-none-any.whl (53 kB)
Collecting sortedcontainers
  Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting sniffio
  Using cached sniffio-1.2.0-py3-none-any.whl (10 kB)
Collecting wsproto>=0.14
  Using cached wsproto-1.0.0-py3-none-any.whl (24 kB)
Collecting certifi
  Using cached certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Collecting cryptography>=1.3.4
  Downloading cryptography-35.0.0-cp36-abi3-win_amd64.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 6.4 MB/s
Collecting pyOpenSSL>=0.14
  Using cached pyOpenSSL-21.0.0-py2.py3-none-any.whl (55 kB)
Collecting pycparser
  Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting six>=1.5.2
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting h11<1,>=0.9.0
  Using cached h11-0.12.0-py3-none-any.whl (54 kB)
Installing collected packages: pycparser, cffi, attrs, sortedcontainers, sniffio, six, outcome, idna, h11, cryptography, async-generator, wsproto, urllib3, trio, pyOpenSSL, certifi, trio-websocket, selenium
Successfully installed async-generator-1.10 attrs-21.2.0 certifi-2021.10.8 cffi-1.15.0 cryptography-35.0.0 h11-0.12.0 idna-3.3 outcome-1.1.0 pyOpenSSL-21.0.0 pycparser-2.20 selenium-4.0.0 six-1.16.0 sniffio-1.2.0 sortedcontainers-2.4.0 trio-0.19.0 trio-websocket-0.9.2 urllib3-1.26.7 wsproto-1.0.0

Linux

# this would happen if python-pip module has not been installed
kim@kim-linux:~$ python -m pip install --upgrade pip
/usr/bin/python: No module named pip

# Install pip for Python3
kim@kim-linux:~$ which pip # check whether pip is indeed not installed
kim@kim-linux:~$ sudo apt-get install -y python3-pip

# Installing selenium
kim@kim-linux:~$ pip install selenium
Collecting selenium
  Downloading selenium-4.0.0-py3-none-any.whl (954 kB)
     |████████████████████████████████| 954 kB 21.5 MB/s 
Collecting urllib3[secure]~=1.26
  Downloading urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 88.3 MB/s 
Collecting trio-websocket~=0.9
  Downloading trio_websocket-0.9.2-py3-none-any.whl (16 kB)
Collecting trio~=0.17
  Downloading trio-0.19.0-py3-none-any.whl (356 kB)
     |████████████████████████████████| 356 kB 15.3 MB/s 
Collecting pyOpenSSL>=0.14; extra == "secure"
  Downloading pyOpenSSL-21.0.0-py2.py3-none-any.whl (55 kB)
     |████████████████████████████████| 55 kB 8.1 MB/s 
Requirement already satisfied: cryptography>=1.3.4; extra == "secure" in /usr/lib/python3/dist-packages (from urllib3[secure]~=1.26->selenium) (2.8)
Requirement already satisfied: certifi; extra == "secure" in /usr/lib/python3/dist-packages (from urllib3[secure]~=1.26->selenium) (2019.11.28)
Requirement already satisfied: idna>=2.0.0; extra == "secure" in /usr/lib/python3/dist-packages (from urllib3[secure]~=1.26->selenium) (2.8)
Collecting async-generator>=1.10
  Downloading async_generator-1.10-py3-none-any.whl (18 kB)
Collecting wsproto>=0.14
  Downloading wsproto-1.0.0-py3-none-any.whl (24 kB)
Collecting sortedcontainers
  Downloading sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting attrs>=19.2.0
  Downloading attrs-21.2.0-py2.py3-none-any.whl (53 kB)
     |████████████████████████████████| 53 kB 6.1 MB/s 
Collecting sniffio
  Downloading sniffio-1.2.0-py3-none-any.whl (10 kB)
Collecting outcome
  Downloading outcome-1.1.0-py2.py3-none-any.whl (9.7 kB)
Requirement already satisfied: six>=1.5.2 in /usr/lib/python3/dist-packages (from pyOpenSSL>=0.14; extra == "secure"->urllib3[secure]~=1.26->selenium) (1.14.0)
Collecting h11<1,>=0.9.0
  Downloading h11-0.12.0-py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 9.1 MB/s 
ERROR: pyopenssl 21.0.0 has requirement cryptography>=3.3, but you'll have cryptography 2.8 which is incompatible.
Installing collected packages: pyOpenSSL, urllib3, async-generator, sortedcontainers, attrs, sniffio, outcome, trio, h11, wsproto, trio-websocket, selenium
Successfully installed async-generator-1.10 attrs-21.2.0 h11-0.12.0 outcome-1.1.0 pyOpenSSL-21.0.0 selenium-4.0.0 sniffio-1.2.0 sortedcontainers-2.4.0 trio-0.19.0 trio-websocket-0.9.2 urllib3-1.26.7 wsproto-1.0.0

Leave a Reply

Your email address will not be published. Required fields are marked *