azure-sdk-for-python
azure-sdk-for-python copied to clipboard
Package Import Issue - Azure AI Text Analytics
- Package Name: azure.ai.textanalytics
- Package Version: 5.3.0b1
- Operating System: Linux
- Python Version: 3.11.1
Describe the bug I have been following the steps in the instructions listed at https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/textanalytics/azure-ai-textanalytics to import Azure Text Analytics but I'm getting an Import error "ImportError: cannot import name 'TokenCredential' from 'azure.core.credentials' (/anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages/azure/core/credentials.py)".
It appears that there is some kind of a dependency issue.
To Reproduce
Steps to reproduce the behavior:
Interaction with the service using the client library begins with a client.
To create a client object, you will need the Cognitive Services or Language service endpoint to
your resource and a credential that allows you access:
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
credential = AzureKeyCredential("<api_key>")
text_analytics_client = TextAnalyticsClient(endpoint="https://<resource-name>.cognitiveservices.azure.com/", credential=credential)
Expected behavior The code should execute and import the required text analytics package
Screenshots

Additional context Add any other context about the problem here.
Hi @markremmey thanks for your issue. It looks like you're using a conda env. Could you please share the output of conda list? azure-ai-textanalytics requires azure-core >= 1.24.0. Also curious - in your issue you say you're using Python 3.11, but it looks like it's using 3.10 in your stack trace - is a different env meant to be used?
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
Hi Krista - it looks like I am on 1.26.1 for Azure Core. And yes you are correct I am on Python 3.10 as you mentioned.

@markremmey thanks for sharing. I ran pip install azure-ai-textanalytics==5.3.0b1 in a conda env and tried this locally in a notebook, but I'm not able to reproduce the error:

Output of my conda list:

My best guess is that there is some venv issue related to how pip was used in a conda environment. There is a good post here which explains how this can lead to broken dependency issues: https://www.anaconda.com/blog/using-pip-in-a-conda-environment
My suggestion is to recreate the conda env using the pip recommendations from the conda docs (https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment) and see if that resolves the dependency issue you're seeing. Let me know if that helps, happy to further troubleshoot with you.
Hi Krista - it is working for me now. Thank you for your help.