Install Python Selenium in macOS

Install Python Selenium in macOS

  1. Install Python Selenium in macOS Using the Package Installer for Python (PIP)
  2. Install Python Selenium in macOS Using a Source Code
  3. Conclusion

The Selenium framework in Python is used to automate tasks like web scraping. This article will discuss two ways to install Selenium in macOS.

Install Python Selenium in macOS Using the Package Installer for Python (PIP)

The Package Installer for Python or PIP is used to install, uninstall, and manage packages in Python. If you have the package installer installed on your machine, you can install Selenium on your macOS using the package installer.

To install Selenium in Python version 2, you can execute the following statement in the command line terminal:

pip install selenium

You can execute the following command to install Selenium in Python version 3.x:

pip3 install selenium

After executing the above command, the Python Selenium framework will be installed on your macOS.

Install Python Selenium in macOS Using a Source Code

Instead of using PIP, you can manually install Selenium using a source code. For this, we will use the following approach.

First, we will download the source code for the Selenium library. For this, we will use the curl command.

The curl command executes a URL in the command line. We will pass the download link of the source code for the Selenium framework to the curl command.

The filename in which the source code has to be downloaded is given after the > operator.

curl https://files.pythonhosted.org/packages/ed/9c/9030520bf6ff0b4c98988448a93c04fcbd5b13cd9520074d8ed53569ccfe/selenium-3.141.0.tar.gz > selenium.tar.gz

After executing the curl command, the source code will be downloaded to our machine in a compressed format in the selenium.tar.gz file.

After downloading the compressed tar.gz file, we will extract the file contents using the tar command. The tar command takes the compressed file’s name as an input argument and extracts the contents into a new folder.

tar -xzvf selenium.tar.gz

After execution, the tar command extracts all the files contained in the compressed file. You can observe this in the following image:

tar Command File Extraction

After extracting the file contents, we will navigate to the newly created folder containing the file contents using the cd command. The cd command takes the name of a directory as its input argument and navigates to the given directory.

cd selenium-3.141.0

cd Selenium Installation

After navigating to the new folder, we will run the setup.py file using the following command. After executing the below command, Selenium will be installed on your macOS.

sudo python setup.py install

The above command will install Selenium in Python version 2.x. You can use the following command to install Selenium into Python version 3.x.

sudo python3 setup.py install

Here, the sudo command runs the statement in admin mode. You will need the administrator password to run this command.

Once the command gets executed successfully, Selenium will be installed on your system. The execution is shown in the image below:

Python Selenium Installation

Conclusion

In this article, we have discussed two ways to install Python Selenium on macOS.

You can use the first approach if you have the Package Installer for Python (PIP) installed in your system. Otherwise, you can install python selenium on your macOS using the second approach.

Related Article - Python Selenium

  • Check if Element Exists Using Selenium Python
  • Python Selenium Refresh Page
  • WebDriverException: Message: Geckodriver Executable Needs to Be in PATH Error in Python
  • Scroll Down Web Page Using Selenium in Python
  • Login to a Website Using Selenium Python