How to install Selenium package in Spyder IDE

Viewed 7495

I've just installed Spyder IDE (only Spyder, not whole Anaconda) at work and would like to automate my work with FireFox.

My question is, how do I install the Selenium package?

2 Answers

(Spyder maintainer here) First, you need to download Miniconda, create an environment and install Selenium on it with conda install selenium. Then you need to connect Spyder to your environment so you can run code that depends on Selenium on it.

The entire process is better described in the second part of our video about managing environments.


I figured it out. Here is instruction for Windows:
  1. Install Python:
    https://www.python.org/downloads/

  2. Install Spyder:
    https://www.spyder-ide.org/

  3. Run PowerShell or CMD:

  4. Insert following commands:

    pip install selenium
    pip install webdriver_manager

  5. Use command "pip freeze", you should see among others, following libraries installed:
    selenium==3.141.0
    urllib3==1.26.2
    webdriver-manager==3.2.2

  6. Open Spyder -> Tools -> PYTHONPATH manager -> Add path
    c:\users\Hronic\appdata\local\programs\python\python39\lib\site-packages

Note:
If you don't know the path, in CMD/PowerShell, type "PIP install selenium"
You will get the answer:
"Requirement already satisfied: urllib3 in c:\users\Hronic\appdata\local\programs\python\python39\lib\site-packages (from selenium) (1.26.2)"

  1. Download webdriver - in my case mozilla:
    https://github.com/mozilla/geckodriver/releases

  2. In Spyder, you can type following code:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    driver = webdriver.Firefox(executable_path=r'C:\Users\Hronic\Downloads\geckodriver.exe')
    driver.get("http://www.python.org")

Note:

  • path to just downloaded driver
  • this short code should open firefox and webpage "http://www.python.org"
  1. It should work or rather "works for me" :)
Related