microsoft/autogen · error · ValueError

Pip install failed. {stdout.decode()}, {stderr.decode()}

Error message

Pip install failed. {stdout.decode()}, {stderr.decode()}

What it means

Raised during LocalCommandLineCodeExecutor function setup when the pip install subprocess exits with a nonzero return code. The message embeds both decoded stdout and stderr of pip, so the actual pip failure (resolution error, no network, bad package name) is visible in the exception text.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/local/__init__.py:312

                asyncio.create_subprocess_exec(
                    py_executable,
                    *cmd_args,
                    cwd=self.work_dir,
                    stdout=asyncio.subprocess.PIPE,
                    stderr=asyncio.subprocess.PIPE,
                )
            )
            cancellation_token.link_future(task)
            try:
                proc = await task
                stdout, stderr = await asyncio.wait_for(proc.communicate(), self._timeout)
            except asyncio.TimeoutError as e:
                raise ValueError("Pip install timed out") from e
            except asyncio.CancelledError as e:
                raise ValueError("Pip install was cancelled") from e

            if proc.returncode is not None and proc.returncode != 0:
                raise ValueError(f"Pip install failed. {stdout.decode()}, {stderr.decode()}")

        # Attempt to load the function file to check for syntax errors, imports etc.
        exec_result = await self._execute_code_dont_check_setup(
            [CodeBlock(code=func_file_content, language="python")], cancellation_token
        )

        if exec_result.exit_code != 0:
            raise ValueError(f"Functions failed to load: {exec_result.output}")

        self._setup_functions_complete = True

    async def execute_code_blocks(
        self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken
    ) -> CommandLineCodeResult:
        """(Experimental) Execute the code blocks and return the result.

        Args:
            code_blocks (List[CodeBlock]): The code blocks to execute.

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Read the embedded pip stderr in the exception - it names the failing package and reason; fix the import name or pin a compatible version.
  2. If offline, pre-install the packages in the target environment or configure an index URL the executor's environment uses.
  3. For private packages, configure credentials (PIP_INDEX_URL, keyring) in the environment the executor shells out to.

Example fix

# before
@register_function
def summarize(text: str) -> str:
    import numpyy  # typo -> pip install fails -> ValueError: Pip install failed.
    ...

# after
@register_function
def summarize(text: str) -> str:
    import numpy
    ...
Defensive patterns

Strategy: try-catch

Validate before calling

import subprocess, sys

def deps_installable(pkgs: list[str]) -> bool:
    r = subprocess.run([sys.executable, "-m", "pip", "install", "--dry-run", *pkgs], capture_output=True)
    return r.returncode == 0

Try / catch

try:
    await executor.execute_code_blocks(blocks, token)
except ValueError as e:
    if "Pip install failed" in str(e):
        log.error("pip failed during setup: %s", str(e))  # stdout/stderr embedded
        raise
    raise

Prevention

When it happens

Trigger: Registering functions with @register_function whose imports name packages that cannot be resolved or installed (typos, private packages without credentials), offline environments where pip cannot reach PyPI, or Python version incompatibilities of the requested packages.

Common situations: Typo'd package names in imports (e.g. 'numpyy'), corporate networks blocking PyPI, private index auth missing, packages without wheels for the running Python version, mismatch between the executor's virtual_env_context Python and package requirements.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/ae672889a67a25d7. Report an issue: GitHub.