{"record":{"id":"bc8f2bb90793df38","repo":"pypa/pip","slug":"no-module-named-module-r","errorCode":null,"errorMessage":"No module named {module!r}","messagePattern":"No module named (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/commands/install.py","lineNumber":97,"sourceCode":"    \"pip._internal.operations.install.wheel\",\n    # Used by rich when emitting output to a legacy Windows console.\n    \"pip._vendor.rich._windows_renderer\",\n)\n\n\n# Imports of standard library modules are always safe: they cannot be\n# shadowed by a distribution pip has just installed.\n_STDLIB_MODULE_NAMES: frozenset[str] = frozenset(sys.stdlib_module_names) | frozenset(\n    sys.builtin_module_names\n)\n\n\ndef _prevent_import_hook(name: str, args: tuple[Any, ...]) -> None:\n    if name != \"import\":\n        return\n    module = args[0]\n    if module in _MISSING_MODULES:\n        raise ImportError(f\"No module named {module!r}\")\n    if module.partition(\".\")[0] in _STDLIB_MODULE_NAMES:\n        return\n    deprecated(\n        reason=f\"Unexpected import of {module!r} after pip install started.\",\n        replacement=None,\n        gone_in=\"26.3\",\n        issue=13842,\n        include_source=True,\n        stacklevel=3,\n    )\n\n\ndef _eagerly_import_modules() -> None:\n    \"\"\"Import modules pip uses lazily so the audit hook ignores them later.\"\"\"\n    for module in _EAGER_IMPORTS:\n        try:\n            __import__(module)\n        except ImportError:","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/commands/install.py#L79-L115","documentation":"Raised by pip's import-audit hook during an install, not by normal user invocation. _prevent_import_hook (install.py:92) is installed via sys.addaudithook during _prevent_further_imports; it blocks re-import of modules recorded in _MISSING_MODULES — modules pip tried to eagerly import (_EAGER_IMPORTS) but that raised ImportError. If something then triggers import of such a module after install began, the hook raises ImportError('No module named {module!r}'). This is a safety mechanism to keep the install process from pulling in unexpected code from a freshly-installed distribution.","triggerScenarios":"A module in _EAGER_IMPORTS (e.g. pip._internal.operations.install.wheel or pip._vendor.rich._windows_renderer) failed to import eagerly and was added to _MISSING_MODULES, then later code (possibly from a wheel being installed) attempts to import it, tripping the audit hook at install.py:96-97.","commonSituations":"A corrupt or partial pip installation where expected internal modules are missing; a wheel whose setup/build code triggers an import that collides with pip's internal modules; unusual packaging that imports pip internals during install.","solutions":["Reinstall/repair pip itself: `python -m ensurepip --upgrade` or `python -m pip install --upgrade --force-reinstall pip`.","Inspect the full traceback to see what triggered the import after install started.","If a specific package's wheel triggers it, report the package interaction to pip's issue tracker.","Avoid installing packages that import pip internals at build/install time."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Health-check that pip's eager-importable modules exist\nimport importlib.util\n\ndef pip_internals_intact():\n    mods = [\n        \"pip._internal.operations.install.wheel\",\n    ]\n    missing = [m for m in mods if importlib.util.find_spec(m) is None]\n    if missing:\n        raise ImportError(\"pip internals missing: %s — repair pip\" % missing)\n    return True\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep pip intact and updated via ensurepip / get-pip.","Avoid installing packages whose build hooks import pip internals.","Inspect the traceback to identify which module triggered the hook."],"tags":["pip-internal","import-audit-hook","installation","safety-mechanism","corrupt-install"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}