{"id":"ddb3bbabf306b831","repo":"pypa/pip","slug":"failed-to-run-pip-under-interpreter-exc","errorCode":null,"errorMessage":"Failed to run pip under {interpreter}: {exc}","messagePattern":"Failed to run pip under (.+?): (.+?)","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/main_parser.py","lineNumber":105,"sourceCode":"            raise CommandError(\n                f\"Could not locate Python interpreter {general_options.python}\"\n            )\n\n        pip_cmd = [\n            interpreter,\n            get_runnable_pip(),\n        ]\n        pip_cmd.extend(args)\n\n        # Set a flag so the child doesn't re-invoke itself, causing\n        # an infinite loop.\n        os.environ[\"_PIP_RUNNING_IN_SUBPROCESS\"] = \"1\"\n        returncode = 0\n        try:\n            proc = subprocess.run(pip_cmd)\n            returncode = proc.returncode\n        except (subprocess.SubprocessError, OSError) as exc:\n            raise CommandError(f\"Failed to run pip under {interpreter}: {exc}\")\n        sys.exit(returncode)\n\n    # --version\n    if general_options.version:\n        sys.stdout.write(parser.version)\n        sys.stdout.write(os.linesep)\n        sys.exit()\n\n    # pip || pip help -> print_help()\n    if not args_else or (args_else[0] == \"help\" and len(args_else) == 1):\n        parser.print_help()\n        sys.exit()\n\n    # the subcommand name\n    cmd_name = args_else[0]\n\n    if cmd_name not in commands_dict:\n        guess = get_similar_commands(cmd_name)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/cli/main_parser.py#L87-L123","documentation":"Raised by parse_command() in main_parser.py:105 when pip fails to spawn a subprocess using the interpreter specified by --python. After locating the interpreter, pip constructs a command list and calls subprocess.run(); if that raises subprocess.SubprocessError or OSError, the error is wrapped with the interpreter path and original exception message.","triggerScenarios":"Calling `pip --python /path/to/python install foo` where the located interpreter exists but cannot execute (e.g., permission denied, corrupt binary, wrong architecture, missing shared libraries). The subprocess.run call at main_parser.py:102 fails.","commonSituations":"The Python binary lacks execute permission. The binary is for a different CPU architecture (e.g., ARM binary on x86). Missing dynamic linker or shared libraries (common with manually compiled Python). The interpreter is a script rather than a binary that can't handle pip's arguments.","solutions":["Check execute permissions: `chmod +x <interpreter>` if needed.","Verify the binary runs: `<interpreter> --version`.","Check for missing shared libraries: `ldd <interpreter>` (Linux).","If architecture mismatch, install a compatible Python build.","Reinstall or rebuild the Python interpreter."],"exampleFix":"# before\npip --python /opt/brokenpython/bin/python install foo\n# error: Failed to run pip under /opt/brokenpython/bin/python: ...\n\n# after\nchmod +x /opt/brokenpython/bin/python\n# or verify and use a working interpreter:\npip --python /usr/bin/python3 install foo","handlingStrategy":"validation","validationCode":"import os, stat\ndef validate_interpreter_executable(path):\n    \"\"\"Check if the interpreter is executable.\"\"\"\n    if not os.path.exists(path):\n        return False\n    if not os.access(path, os.X_OK):\n        return False\n    return stat.S_ISREG(os.stat(path).st_mode)","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import CommandError\ntry:\n    # pip --python <interpreter> install ...\nexcept CommandError as e:\n    if 'Failed to run pip under' in str(e):\n        # check permissions, architecture, shared libs\n","preventionTips":["Verify the interpreter runs: execute `<path> --version` before using --python.","Check execute permissions on the binary.","On Linux, use `ldd` to verify shared library dependencies."],"tags":["cli","python-interpreter","subprocess","permissions","execution"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}