Beautiful SoupUsing Package Installer for Python (PIP)
Beautiful SoupUsing Advanced Package Tool (APT)
Beautiful Soupby Manually Downloading Source Codes
Beautiful Soupby Using
Python provides us with various libraries and modules to perform different tasks.
Beautiful Soup library is used in Python to scrape HTML and XML files.
This article will discuss different ways to install the
Beautiful Soup library in Python.
Beautiful Soup Using Package Installer for Python (PIP)
To install the
Beautiful Soup library using PIP, you can execute the following command in the command line terminal on your machine.
pip install beautifulsoup4
The above command, after execution, will install the
beautiful soup library on your machine. If you’re using Python
3.x on the same machine, the above command will install the
beautiful soup library into your Python
To install the
beautiful soup library in the Python
3.x directory, you can run the following command in the command line terminal.
pip3 install beautifulsoup4
Beautiful Soup Using Advanced Package Tool (APT)
APT is used to handle software packages efficiently. You will require the computer’s administrator password to install the
beautiful soup library using APT.
beautiful soup using APT, you must execute the following command in the command line terminal.
sudo apt-get install python-bs4
sudo keyword is used to run the command in superuser, i.e., administrator mode. Without using the
sudo command, you will be unable to install any software on your machine.
Again, if you have multiple Python versions installed on your machine, the above command will install the
beautiful soup library into Python 2’s directory. To install the
beautiful soup library in Python 3, you can use the following command.
sudo apt-get install python3-bs4
Beautiful Soup by Manually Downloading Source Codes
To install the
beautiful soup library in Python using the source code, you first need to download the source code from this link. You will get a compressed file from the link.
After downloading the file, you must go to the directory where the file has been downloaded. Then, you need to extract the files from the downloaded compressed file.
Once you extract all the files, you need to go to the folder in which the files have been extracted. There, you will find a file named
You must run the command line terminal in the current directory where
Next, you need to run the
setup.pyfile using the following command in the terminal.
After running the above command, the
beautiful souplibrary will be installed in your Python 2’s directory. To install the
beautiful souplibrary in Python 3, you can run
setup.pyusing Python 3 by executing the following command in the command line terminal.
Remember to execute the commands by opening the terminal in the same directory where
setup.py is stored. Otherwise, you will face errors.
Beautiful Soup by Using
tar in Linux
wget command executes a URL to download a file using the command line. Also, the
tar command is used to unzip a compressed file using the command line.
We will use the following steps to install the
beautiful soup library using the
wget command and the
First, we will execute the
wgetcommand with the download link of the source code of the
beautiful souplibrary, as shown below.
After downloading the compressed file, we will use the
tarcommand to extract the contents of the compressed file, as shown below.
tar -xvzf beautifulsoup4-4.0.0b3.tar.gz
tarcommand is executed, we will execute the
setup.pyfile using the following command.
python setup.py install
When the above command is executed, the
beautiful souplibrary is installed in the directory of Python 2 if there are different Python versions installed on your machine. To install the library in the Python 3 directory, you can use the following command.
python3 setup.py install
To verify the installation of the
beautiful soup module, you can use the
import statement in your program, as shown below.
If executing the above statement in a Python program doesn’t cause any error, the
beautiful soup library has been successfully installed on your machine.
Out of all the methods discussed in this article, we suggest you use the package installer for Python (PIP) or Advanced Package Tool (APT) to install the
beautiful soup library on your machine. This will help you avoid errors like version mismatch or absence of dependencies because PIP and APT handle these things for you.