{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/commands/install.py#L79-L115","documentation":"Raised by the audit hook _prevent_import_hook (install.py:92-97), installed via _prevent_further_imports during pip install. pip eagerly imports known lazy modules first; any that fail are recorded in _MISSING_MODULES. The hook then raises ImportError for any later 'import' audit event whose target is in that set, so that a freshly installed distribution cannot trigger an import pip already knows is broken. End users normally never see it; it surfaces when pip's own vendored/required modules are missing or corrupted and something triggers their import mid-install.","triggerScenarios":"During a pip install, after sys.addaudithook is registered, any code path (including a wheel's setup or an import inside pip) that does importlib.import_module / __import__ of a module recorded in _MISSING_MODULES. The set is populated by _eagerly_import_modules failing to import one of the _EAGER_IMPORTS (e.g. pip._internal.operations.install.wheel or pip._vendor.rich._windows_renderer).","commonSituations":"A corrupted/truncated pip installation where a vendored module (e.g. rich._windows_renderer) is missing; partial uninstall of pip; a broken filesystem; running a monkeypatched/forked pip; a wheel post-install hook that imports a module pip flagged missing.","solutions":["Reinstall/repair pip itself: python -m ensurepip --upgrade or download get-pip.py and run it.","Run pip with -vv to see which module is reported missing in the traceback, then restore that file from a fresh pip wheel.","Avoid running a partially deleted pip tree; install pip into a clean virtualenv: python -m venv /tmp/pipfix && /tmp/pipfix/bin/pip install --upgrade pip.","If you maintain a forked/vendored pip, ensure the modules in _EAGER_IMPORTS are importable."],"exampleFix":"// before\n# pip tree is corrupted: pip/_vendor/rich/_windows_renderer.py deleted\npip install requests  # raises ImportError: No module named 'pip._vendor.rich._windows_renderer'\n// after\ncurl -sS https://bootstrap.pypa.io/get-pip.py | python\ntpip install requests","handlingStrategy":"validation","validationCode":"# Sanity-check pip's vendored tree is intact before relying on pip install\nimport importlib.util, sys\nfor mod in (\"pip._internal.operations.install.wheel\",):\n    if importlib.util.find_spec(mod) is None:\n        raise SystemExit(f\"pip install is corrupted: {mod} missing; reinstall pip via get-pip.py\")","typeGuard":null,"tryCatchPattern":"# In a wrapper, catch ImportError from pip and prompt a self-repair\ntry:\n    run_pip([\"install\", pkg])\nexcept ImportError as e:\n    if \"No module named\" in str(e):\n        print(\"pip appears corrupted; run: python -m ensurepip --upgrade\", file=sys.stderr)\n        raise","preventionTips":["Install pip into a clean virtualenv rather than mutating a system tree.","Repair pip with 'python -m ensurepip --upgrade' or get-pip.py if vendored modules go missing.","Avoid partial uninstalls of pip; never delete files under site-packages/pip manually."],"tags":["pip","install","internal-error","import-error","audit-hook","corrupted-install"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}