ModuleNotFoundError: No module named 'yaml' (tested fix)
ModuleNotFoundError: No module named 'yaml' means PyYAML is not installed for the Python running your script. The import name is yaml, the package is PyYAML. We tested both names on Python 3.14.
1. Cause: the package is called PyYAML
We ran this script in a fresh python:3-alpine container (Python 3.14.7):
python -c "import yaml" 2>&1 | tail -1
echo "--- pip install yaml"
pip install -q --disable-pip-version-check --root-user-action=ignore yaml 2>&1 | tail -1
echo "--- pip install pyyaml"
pip install -q --disable-pip-version-check --root-user-action=ignore pyyaml 2>&1 | tail -1
pip list --disable-pip-version-check 2>/dev/null | grep -i yaml
python -c "import yaml; print(yaml.__version__, yaml.safe_load('a: 1\nb: [x, y]'))"
Output:
ModuleNotFoundError: No module named 'yaml'
--- pip install yaml
ERROR: No matching distribution found for yaml
--- pip install pyyaml
PyYAML 6.0.3
6.0.3 {'a': 1, 'b': ['x', 'y']}
The module is yaml, but the PyPI package is PyYAML (pip ignores the case, so pip install pyyaml works). pip install yaml finds nothing. If it still fails after installing, you installed it for a different Python: use python -m pip install pyyaml with the interpreter (or activated venv) that runs your code, and add PyYAML to requirements.txt.
2. The next two errors after the import works
import yaml
doc = "port: 08\nversion: 1.10\ncountry: NO\n"
print(yaml.safe_load(doc))
try:
yaml.load(doc)
except TypeError as e:
print("TypeError:", e)
Output:
{'port': '08', 'version': 1.1, 'country': False}
TypeError: load() missing 1 required positional argument: 'Loader'
yaml.load() without a Loader is an error in PyYAML 6, so old tutorials break; use yaml.safe_load() for config and untrusted input. And YAML 1.1 rules apply: 1.10 became the float 1.1, NO became False, and 08 stayed a string. Quote values that must stay strings: version: "1.10", country: "NO".
Related: ComfyUI: No module named 'yaml' (wrong Python) · YAML: mapping values are not allowed here · No module named 'dotenv' · ModuleNotFoundError vs ImportError.
Frequently asked questions
How do I fix No module named yaml?
Run python -m pip install pyyaml with the same interpreter (or activated venv) that runs your code.
Why does pip install yaml fail?
There is no installable package called yaml on PyPI; pip says No matching distribution found. The package is PyYAML.
Why does yaml.load() say missing argument Loader?
PyYAML 6 requires a Loader. Use yaml.safe_load(text), or yaml.load(text, Loader=yaml.SafeLoader).
Written with AI assistance. Measured on 2026-10-22 in the official python:3-alpine image (Python 3.14.7): importing yaml before and after pip install yaml (no such package) and pip install pyyaml (PyYAML 6.0.3), safe_load vs load without Loader, and YAML 1.1 type surprises. Every block was run verbatim and its output pasted unedited. PlainHeaders is our extension; Python and PyYAML are free.