How to Install Python Selenium in macOS
- Install Python Selenium in macOS Using the Package Installer for Python (PIP)
- Install Python Selenium in macOS Using a Source Code
- 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:
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
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:
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.
Aditya Raj is a highly skilled technical professional with a background in IT and business, holding an Integrated B.Tech (IT) and MBA (IT) from the Indian Institute of Information Technology Allahabad. With a solid foundation in data analytics, programming languages (C, Java, Python), and software environments, Aditya has excelled in various roles. He has significant experience as a Technical Content Writer for Python on multiple platforms and has interned in data analytics at Apollo Clinics. His projects demonstrate a keen interest in cutting-edge technology and problem-solving, showcasing his proficiency in areas like data mining and software development. Aditya's achievements include securing a top position in a project demonstration competition and gaining certifications in Python, SQL, and digital marketing fundamentals.
GitHub