How to Install PyYAML in Python

v6.0.3 General Purpose Python >=3.8 MIT

YAML parser and emitter for Python

Install pip install PyYAML

What is PyYAML?

YAML parser and emitter for Python

YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python.

PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object.

PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence.

Quick Start

Minimal example to get started with PyYAML:

import yaml

data = {"name": "Alice", "age": 30, "active": True}

# Serialize to YAML string
text = yaml.dump(data)
print(text)

# Parse YAML back to dict
parsed = yaml.safe_load(text)
print(parsed["name"])  # Alice

Installation

pip (standard)

pip install PyYAML

Virtual environment (recommended)

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

pip3

pip3 install PyYAML

conda

conda install -c conda-forge PyYAML

Poetry

poetry add PyYAML

Verify the Installation

After installing, confirm the package is available:

python -c "import yaml; print(yaml.__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 PyYAML with pip.

ModuleNotFoundError: No module named 'yaml'

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

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

ModuleNotFoundError: No module named 'yaml' (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 PyYAML to install into the interpreter you are running.

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

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

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

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 PyYAML. 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 PyYAML

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 PyYAML

Recent Releases

VersionReleased
6.0.3 latest 2025-09-25
6.0.2 2024-08-06
6.0.2rc1 2024-06-10
6.0.1 2023-07-17
6.0 2021-10-13

Full release history on PyPI →

Manage PyYAML

Upgrade to latest version

pip install --upgrade PyYAML

Install a specific version

pip install PyYAML==6.0.3

Uninstall

pip uninstall PyYAML

Check what is installed

pip show PyYAML

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