ModuleNotFoundError: No module named 'aiohttp' when using async DocumentAnalysisClient
Package Name: azure-ai-formrecognizer
- Package Version: 3.3.3
- Operating System: Linux
- Python Version: 3.10
Describe the bug When using the async version of DocumentAnalysisClient from azure.ai.formrecognizer.aio, the application fails with ModuleNotFoundError: No module named 'aiohttp' even though aiohttp is not listed as a dependency in the package metadata.
To Reproduce Steps to reproduce the behavior:
- Install azure-ai-formrecognizer==3.3.3 with only its declared dependencies
- Create a Python script with async DocumentAnalysisClient:
from azure.ai.formrecognizer.aio import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential
async def test_client():
async with DocumentAnalysisClient(
endpoint="https://example.cognitiveservices.azure.com/",
credential=AzureKeyCredential("key")
) as client:
pass
- Run the script
- Error occurs when trying to instantiate the async client
Expected behavior The async DocumentAnalysisClient should work without requiring manual installation of unlisted dependencies, or the package should clearly declare aiohttp as a dependency for async functionality.
Screenshots Full stack trace:
File "referral_extraction/utils/ocr.py", line 61, in parse_document_standard
async with DocumentAnalysisClient(
File ".../azure/ai/formrecognizer/aio/_document_analysis_client_async.py", line 66, in __init__
super().__init__(
File ".../azure/ai/formrecognizer/aio/_form_base_client_async.py", line 79, in __init__
self._client = FormRecognizer(
File ".../azure/ai/formrecognizer/_generated/aio/_form_recognizer_client.py", line 99, in __init__
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
File ".../azure/core/_pipeline_client_async.py", line 166, in __init__
self._pipeline = pipeline or self._build_pipeline(self._config, **kwargs)
File ".../azure/core/_pipeline_client_async.py", line 260, in _build_pipeline
from .pipeline.transport._aiohttp import AioHttpTransport
File ".../azure/core/pipeline/transport/_aiohttp.py", line 45, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
Additional context
- Package metadata shows dependencies: azure-common, azure-core, msrest, typing-extensions (no aiohttp)
- The async client internally uses azure-core's AioHttpTransport which requires aiohttp
- Current workaround: manually install aiohttp
- This affects runtime behavior and creates poor developer experience with unclear error messaging
- Similar pattern may affect other Azure SDK packages with async support
@vkurpad @yungshinlintw
I am seeing the same error when invoking DefaultAzureCredential. Here are my installed versions of azure projects:
azure-core 1.35.0
azure-core-tracing-opentelemetry 1.0.0b12
azure-cosmos 4.9.0
azure-identity 1.24.0
azure-monitor-opentelemetry 1.8.0
azure-monitor-opentelemetry-exporter 1.0.0b41
azure-storage-blob 12.26.0
And here are my dependencies (among others) for pyproject.toml:
"azure-cosmos>=4.9.0",
"azure-identity>=1.24.0",
"azure-storage-blob>=12.26.0",
From https://learn.microsoft.com/en-us/python/api/overview/azure/ai-documentintelligence-readme?view=azure-python#examples
You need to install aiohttp explicitly.
Hi @Kevv-J. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Hi @Kevv-J, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.