{"record":{"id":"ad57120d0db571b5","repo":"microsoft/autogen","slug":"packages-unavailable-in-environment-missing-pkgs","errorCode":null,"errorMessage":"Packages unavailable in environment: {missing_pkgs}","messagePattern":"Packages unavailable in environment: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py","lineNumber":250,"sourceCode":"\n    async def _setup_functions(self, cancellation_token: CancellationToken) -> None:\n        if not self._func_code:\n            self._func_code = build_python_functions_file(self._functions)\n\n            # Check required function imports and packages\n            lists_of_packages = [x.python_packages for x in self._functions if isinstance(x, FunctionWithRequirements)]\n            # Should we also be checking the imports?\n\n            flattened_packages = [item for sublist in lists_of_packages for item in sublist]\n            required_packages = set(flattened_packages)\n\n            if self._available_packages is None:\n                await self._populate_available_packages(cancellation_token)\n\n            if self._available_packages is not None:\n                missing_pkgs = set(required_packages - self._available_packages)\n                if len(missing_pkgs) > 0:\n                    raise ValueError(f\"Packages unavailable in environment: {missing_pkgs}\")\n\n        func_file = self.work_dir / f\"{self._functions_module}.py\"\n        func_file.write_text(self._func_code)\n\n        # Attempt to load the function file to check for syntax errors, imports etc.\n        exec_result = await self._execute_code_dont_check_setup(\n            [CodeBlock(code=self._func_code, language=\"python\")], cancellation_token\n        )\n\n        if exec_result.exit_code != 0:\n            raise ValueError(f\"Functions failed to load: {exec_result.output.strip()}\")\n\n        self._setup_functions_complete = True\n\n    async def _setup_cwd(self, cancellation_token: CancellationToken) -> None:\n        # Change the cwd to /mnt/data to properly have access to uploaded files\n        exec_result = await self._execute_code_dont_check_setup(\n            [CodeBlock(code=\"import os; os.chdir('/mnt/data')\", language=\"python\")], cancellation_token","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py#L232-L268","documentation":"During setup, AzureContainerCodeExecutor diffs the python_packages declared on registered FunctionWithRequirements objects against the packages found inside its container (via get_available_packages). Any missing package raises ValueError listing the set difference — the container image is immutable at run time, so absent packages cannot be pip-installed on the fly.","triggerScenarios":"Registering functions_module functions via functions=[FunctionWithRequirements(python_packages=['some_pkg'], ...)] where some_pkg is not baked into the container image used by the executor; also triggered by name mismatch (case-sensitive set difference, e.g. 'Sklearn' vs 'scikit-learn').","commonSituations":"Custom container images missing a dependency you later added to function requirements, package-name vs distribution-name mismatches (beautifulsoup4 vs bs4, scikit-learn vs sklearn), stale pool images after requirements grew.","solutions":["Add the missing packages to the container image and rebuild/recreate the pool","Or use the default autogen container image, which installs declared packages at pool creation","Fix names in python_packages to match PyPI distribution names exactly (e.g. 'scikit-learn' not 'sklearn')","Remove requirements for packages your functions don't actually import"],"exampleFix":"# before\nfn = FunctionWithRequirements(func=analyze, python_packages=['sklearn'])  # not a distribution name\n\n# after\nfn = FunctionWithRequirements(func=analyze, python_packages=['scikit-learn', 'numpy'])","handlingStrategy":"validation","validationCode":"async def all_requirements_available(executor, functions, token) -> bool:\n    required = {p for f in functions if isinstance(f, FunctionWithRequirements) for p in f.python_packages}\n    available = await executor.get_available_packages(token)\n    return required <= available","typeGuard":null,"tryCatchPattern":"try:\n    await executor.execute_code(blocks, token)\nexcept ValueError as e:\n    if 'Packages unavailable in environment' in str(e):\n        raise RuntimeError('bake missing packages into the container image or fix distribution names') from e\n    raise","preventionTips":["Use exact PyPI distribution names in python_packages (scikit-learn, beautifulsoup4)","Sync the container image build with the functions' requirements list in CI","Run the availability diff as a startup check before dispatching work"],"tags":["azure","code-executor","container","dependencies","setup"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}