How to Install BeautifulSoup
BeautifulSoup is distributed as the beautifulsoup4 package on PyPI. The naming is a frequent source of confusion: you install beautifulsoup4 but import from bs4. There was an older version called simply BeautifulSoup (version 3), which is no longer maintained and should not be used. Always install beautifulsoup4 for new projects. The current release as of mid-2026 is version 4.14.x, and it requires Python 3.7 or higher.
Step 1: Check Your Python Version
BeautifulSoup 4 requires Python 3.7 or newer. Open your terminal (Command Prompt on Windows, Terminal on macOS or Linux) and run:
python --version
If this shows Python 2.x or a "command not found" error, try python3 --version instead. On many Linux distributions and macOS, python points to Python 2 while python3 points to Python 3. You need to see something like Python 3.9.7 or higher.
If Python is not installed at all, download it from python.org. On macOS, you can also install it through Homebrew with brew install python3. On Ubuntu and Debian, use sudo apt install python3 python3-pip. On Windows, the Microsoft Store offers a one-click Python installation that automatically adds Python to your PATH.
Make sure pip is available too. Run pip --version or pip3 --version. Pip comes bundled with Python 3.4 and later, so if you have a recent Python, pip should already be there. If it is missing, run python -m ensurepip --upgrade to install it.
Step 2: Create a Virtual Environment
A virtual environment gives your project its own isolated set of Python packages. This prevents version conflicts between projects and keeps your system Python clean. While not strictly required, using a virtual environment is a strong best practice for any Python project.
Navigate to your project directory and run:
python -m venv venv
This creates a venv folder containing a self-contained Python installation. Activate it with the command for your operating system. On macOS and Linux: source venv/bin/activate. On Windows Command Prompt: venv\Scripts\activate. On Windows PowerShell: .\venv\Scripts\Activate.ps1.
When the environment is active, your terminal prompt changes to show (venv) at the beginning. All pip commands now install packages into this environment rather than your global Python installation. To leave the virtual environment later, simply run deactivate.
If you are using Anaconda or Miniconda, create a conda environment instead: conda create -n scraping python=3.11, then activate it with conda activate scraping. Conda environments work the same way conceptually but use conda's own package management system alongside pip.
Step 3: Install BeautifulSoup with pip
With your virtual environment active, install BeautifulSoup:
pip install beautifulsoup4
This downloads the latest version from PyPI and installs it along with its dependency, soupsieve, which provides CSS selector support. The installation is quick because BeautifulSoup is a pure Python package with no compiled extensions.
If you need a specific version, pin it: pip install beautifulsoup4==4.14.3. For production projects, it is good practice to pin your versions in a requirements.txt file so that every team member and deployment environment uses the same packages. Run pip freeze > requirements.txt to generate this file after installing everything you need.
On systems where both Python 2 and Python 3 are installed, you may need to use pip3 instead of pip to ensure packages install into the Python 3 environment. Inside a virtual environment, pip always points to the correct version.
Step 4: Install a Parser
BeautifulSoup does not parse HTML by itself. It delegates parsing to an underlying library, and you choose which one to use. There are three options, each with different trade-offs.
html.parser is Python's built-in parser. It requires no installation because it ships with Python itself. It is adequate for most scraping tasks, moderately fast, and handles common forms of broken HTML. If you want the simplest setup with no extra dependencies, you can skip this step and use html.parser.
lxml is a C-based parser that is significantly faster. Install it with pip install lxml. On most systems this installs a pre-compiled binary, so no C compiler is needed. If the binary is not available for your platform, pip will try to compile from source, which requires libxml2-dev and libxslt-dev on Linux. For production scraping where you process many pages, lxml is the recommended choice.
html5lib parses HTML exactly like a web browser, following the WHATWG HTML5 specification. Install it with pip install html5lib. It is the slowest parser but produces the most accurate tree for severely broken HTML. Use it when you need absolute fidelity to how browsers interpret markup.
You can install all three and switch between them by passing different parser names to the BeautifulSoup constructor. For most developers, installing lxml alongside the built-in html.parser gives you the best combination of speed and compatibility.
Step 5: Install the Requests Library
BeautifulSoup parses HTML, but it does not fetch web pages. You need a separate HTTP library, and requests is the standard choice in the Python ecosystem:
pip install requests
With requests installed, you can fetch any web page with requests.get(url) and pass the response HTML directly to BeautifulSoup. The two libraries complement each other perfectly and are almost always used together.
You can install everything at once with a single command: pip install beautifulsoup4 requests lxml. This gives you the complete stack for most web scraping projects. For more advanced HTTP handling, consider httpx as an alternative to requests, as it supports HTTP/2 and async requests.
Step 6: Verify the Installation
Open a Python shell by running python in your terminal and test the import:
from bs4 import BeautifulSoup
If no error appears, the library is installed correctly. Test parsing with a quick example:
soup = BeautifulSoup('<p>Hello</p>', 'html.parser')
print(soup.p.string)
This should print Hello. If you installed lxml, try changing the parser argument to 'lxml' to confirm that parser works too.
To verify requests is working, try fetching a test page: import requests followed by r = requests.get('https://httpbin.org/get'). If r.status_code returns 200, your full scraping stack is ready.
Troubleshooting Common Installation Errors
ModuleNotFoundError: No module named 'bs4'. This means BeautifulSoup is not installed in the Python environment you are running. Check that your virtual environment is activated. If you installed with pip3 but are running python (which might point to Python 2), there is a mismatch. Use python3 to start your script, or verify with pip show beautifulsoup4 that the package is installed in the right environment.
ImportError: No module named 'beautifulsoup4'. You are trying to import the wrong name. The package is called beautifulsoup4 on PyPI, but the import statement is from bs4 import BeautifulSoup. This is the most common beginner mistake.
FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. You specified 'lxml' as your parser but lxml is not installed. Either install it with pip install lxml or switch to 'html.parser' which requires no extra installation.
lxml compilation errors on Linux. If pip cannot find a pre-built lxml wheel for your platform, it tries to compile from source, which requires C development headers. Install them with sudo apt install libxml2-dev libxslt-dev python3-dev on Ubuntu/Debian or sudo yum install libxml2-devel libxslt-devel python3-devel on CentOS/RHEL, then retry pip install lxml.
Permission denied errors. If you get permission errors without a virtual environment, do not use sudo pip install as this can break system packages. Instead, create a virtual environment (Step 2 above) and install packages there, or use pip install --user beautifulsoup4 to install into your user directory.
Installing in Different Environments
Anaconda. If you use Anaconda, BeautifulSoup is already included in the default distribution. You can verify with conda list beautifulsoup4. If you need to install or update it, use conda install beautifulsoup4 or conda install -c conda-forge beautifulsoup4 for the latest version.
Jupyter Notebooks. From within a Jupyter notebook, you can install packages using a cell with !pip install beautifulsoup4 requests lxml. The exclamation mark runs the command in the underlying shell. For environments like Google Colab, BeautifulSoup and requests are typically pre-installed, so you can import them directly without installation.
Docker. In a Dockerfile, add RUN pip install beautifulsoup4 requests lxml after your base Python image setup. Using a requirements.txt file is cleaner for larger projects: COPY requirements.txt . followed by RUN pip install -r requirements.txt.
Install with pip install beautifulsoup4 requests lxml inside a virtual environment. Import with from bs4 import BeautifulSoup. The most common errors come from the package/import name mismatch and missing parsers.