## TL;DR

The pip package is called PyYAML but you import it as yaml. Run pip install pyyaml, then import yaml works. If it still fails, youre installing into a different python than the one running your code, which is the cause nine times out of ten.

## The error

```text
ModuleNotFoundError: No module named 'yaml'
```

## Fix it

1. Run `pip install pyyaml` in the same environment that runs your code.
   Expected: pip prints Successfully installed PyYAML-x.y.z

2. Verify with `python -c "import yaml; print(yaml.__version__)"`.
   Expected: prints a version like 6.0.2 with no error

3. If it still fails, compare `which python` with `pip -V` (or `python -m pip install pyyaml` to force the right one).
   Expected: both point at the same environment; the import then works

## When this applies

- python raises ModuleNotFoundError: No module named 'yaml' on import yaml
- you ran pip install yaml or pip install PyYAML and it still fails

## When it does NOT apply

- yaml parses but throws errors (thats a content problem, not an install problem)
- TypeError about Loader (different skill, see the yaml.load Loader fix)

## Tool and version notes

PyYAML 5.x and 6.x, Python 3.8+. The import name has been yaml forever; the PyPI name is PyYAML (pip install is case-insensitive, pyyaml works).

## Other ways this shows up

### ModuleNotFoundError: No module named 'yaml' inside a virtualenv

The venv was created without system packages and PyYAML was installed globally. Activate the venv first, then pip install pyyaml inside it.

### ImportError: No module named yaml (older python wording)

Same fix. Python 3.6+ says ModuleNotFoundError, older versions say ImportError.

## Why it happens

PyPI distribution names and import names dont have to match, and here they dont: the project is PyYAML, the top-level module is yaml. pip install yaml installs a totally different stub package, which is why guessing the name fails.

## Edge cases

- On Debian/Ubuntu, apt install python3-yaml also works but gives you an older version.
- If youre on conda, conda install pyyaml avoids compiler hassles for the optional C loader.

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_nicWch2DE4YMGHyq7l694g/versions/skv_d4AQH0w7QYo7NcAlfeDOtQ>
- Canonical HTML skill page: <https://vectle.com/skills/skl_nicWch2DE4YMGHyq7l694g>
- Current Markdown URL: <https://vectle.com/skills/skl_nicWch2DE4YMGHyq7l694g/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "issueatlas",
  "client": null,
  "notices_and_references": [
    "https://pytutorial.com/how-to-solve-modulenotfounderror-no-module-named-yaml/"
  ]
}
```
