How to Install MarkupSafe in Python

v3.0.3 Web & HTTP Python >=3.9

Safely add untrusted strings to HTML/XML markup.

Install pip install MarkupSafe

What is MarkupSafe?

Safely add untrusted strings to HTML/XML markup.

MarkupSafe implements a text object that escapes characters so it is safe to use in HTML and XML. Characters that have special meanings are replaced so that they display as the actual characters. This mitigates injection attacks, meaning untrusted user input can safely be displayed on a page.

The Pallets organization develops and supports MarkupSafe and other popular packages. In order to grow the community of contributors and users, and allow the maintainers to devote more time to the projects, [please donate today][].

See our [detailed contributing documentation][contrib] for many ways to contribute, including reporting issues, requesting features, asking or answering questions, and making PRs.

Quick Start

Minimal example to get started with MarkupSafe:

import markupsafe

print(markupsafe.__version__)

Installation

pip (standard)

pip install MarkupSafe

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install MarkupSafe

pip3

pip3 install MarkupSafe

conda

conda install -c conda-forge MarkupSafe

Poetry

poetry add MarkupSafe

Verify the Installation

After installing, confirm the package is available:

python -c "import markupsafe; print(markupsafe.__version__)"

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing MarkupSafe with pip.

ModuleNotFoundError: No module named 'markupsafe'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install MarkupSafe. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'markupsafe' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install MarkupSafe to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'markupsafe'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show MarkupSafe and upgrade with pip install --upgrade MarkupSafe.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install MarkupSafe. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user MarkupSafe

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org MarkupSafe

ConnectionError: Failed to establish a new connection

Cause: Server unreachable, URL invalid, or firewall/proxy blocking the connection.

Fix: Verify the URL and network access. Set HTTP_PROXY / HTTPS_PROXY env vars if behind a proxy.

SSLError: CERTIFICATE_VERIFY_FAILED

Cause: The remote server's SSL certificate cannot be verified.

Fix: Update CA certificates on your system. For testing only, disable SSL verification (never in production).

Recent Releases

VersionReleased
3.0.3 latest 2025-09-27
3.0.2 2024-10-18
3.0.1 2024-10-08
3.0.0 2024-10-07
2.1.5 2024-02-02

Full release history on PyPI →

Manage MarkupSafe

Upgrade to latest version

pip install --upgrade MarkupSafe

Install a specific version

pip install MarkupSafe==3.0.3

Uninstall

pip uninstall MarkupSafe

Check what is installed

pip show MarkupSafe

Last updated: 2026-04-11 • Data from PyPI