microsoft/autogen · error · ValueError
Packages unavailable in environment: {missing_pkgs}
Error message
Packages unavailable in environment: {missing_pkgs} What it means
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.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py:250
async def _setup_functions(self, cancellation_token: CancellationToken) -> None:
if not self._func_code:
self._func_code = build_python_functions_file(self._functions)
# Check required function imports and packages
lists_of_packages = [x.python_packages for x in self._functions if isinstance(x, FunctionWithRequirements)]
# Should we also be checking the imports?
flattened_packages = [item for sublist in lists_of_packages for item in sublist]
required_packages = set(flattened_packages)
if self._available_packages is None:
await self._populate_available_packages(cancellation_token)
if self._available_packages is not None:
missing_pkgs = set(required_packages - self._available_packages)
if len(missing_pkgs) > 0:
raise ValueError(f"Packages unavailable in environment: {missing_pkgs}")
func_file = self.work_dir / f"{self._functions_module}.py"
func_file.write_text(self._func_code)
# Attempt to load the function file to check for syntax errors, imports etc.
exec_result = await self._execute_code_dont_check_setup(
[CodeBlock(code=self._func_code, language="python")], cancellation_token
)
if exec_result.exit_code != 0:
raise ValueError(f"Functions failed to load: {exec_result.output.strip()}")
self._setup_functions_complete = True
async def _setup_cwd(self, cancellation_token: CancellationToken) -> None:
# Change the cwd to /mnt/data to properly have access to uploaded files
exec_result = await self._execute_code_dont_check_setup(
[CodeBlock(code="import os; os.chdir('/mnt/data')", language="python")], cancellation_tokenView on GitHub (pinned to 027ecf0a37)
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
Example fix
# before fn = FunctionWithRequirements(func=analyze, python_packages=['sklearn']) # not a distribution name # after fn = FunctionWithRequirements(func=analyze, python_packages=['scikit-learn', 'numpy'])
Defensive patterns
Strategy: validation
Validate before calling
async def all_requirements_available(executor, functions, token) -> bool:
required = {p for f in functions if isinstance(f, FunctionWithRequirements) for p in f.python_packages}
available = await executor.get_available_packages(token)
return required <= available Try / catch
try:
await executor.execute_code(blocks, token)
except ValueError as e:
if 'Packages unavailable in environment' in str(e):
raise RuntimeError('bake missing packages into the container image or fix distribution names') from e
raise Prevention
- 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
When it happens
Trigger: 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').
Common situations: 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.
Related errors
- Failed to get list of available packages: {ret.output.strip(
- Dependencies for AzureAIAgent not found. Please install auto
- Timeout must be greater than or equal to 1.
- Functions failed to load: {exec_result.output.strip()}
- Pip install failed. {stdout.decode()}, {stderr.decode()}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/ad57120d0db571b5.
Report an issue: GitHub.