Ptvs: Unable to import Azure Cognitive Services package

Created on 21 Jun 2018  路  7Comments  路  Source: microsoft/PTVS

Hello all,

I am trying to use azure cognitive services. In the standard code, while importing the package, I am getting the following error:

Traceback (most recent call last):
File "azure-traning.py", line 1, in
from azure.cognitiveservices.vision.customvision.training import training_api
File "C:\Users\Asus\Desktopnodejs\azure.py", line 1, in
from azure.cognitiveservices.vision.customvision.prediction import prediction_endpoint
ModuleNotFoundError: No module named 'azure.cognitiveservices'; 'azure' is not a package

I am not able to understand this. Please help.

I have done:

  1. pip install azure
  2. pip install azure-cognitiveservices-vision-customvision
question

Most helpful comment

I was also getting the same original issue (ModuleNotFoundError: No module named 'azure.cognitiveservices') for the spellcheck functions. Do NOT pip install azure . It installs all of the subpackages and I have a feeling there is an overlap between them that is causing issues.

I couldn't easily remove all the sub packages so I wiped my environment, started fresh, and this time only installed the pack I wanted (in this case pip install azure-cognitiveservices-language-spellcheck).

Now I am able to from azure.cognitiveservices.language.spellcheck import SpellCheckAPI without problem

All 7 comments

You've named one of your project files azure.py, which conflicts with the name of a package you are trying to import. So it's trying to load things from your file rather than site-packages.

Thank you for the above advise.
I have made the required changes in the file name and was getting the below error. So is it a problem of the api-key?

Traceback (most recent call last):
File "train_cm.py", line 12, in
project = trainer.create_project("PneumoniaNormal")
File "C:\Users\Asus\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\cognitiveservices\vision\customvision\training\training_api.py", line 1537, in create_project
raise HttpOperationError(self._deserialize, response)
msrest.exceptions.HttpOperationError: Operation returned an invalid status code 'Access Denied'

It could be. Please check their tutorial if you haven't done so already, and if you need further help with their SDK, I've included the support page.

tutorial: https://docs.microsoft.com/en-us/azure/cognitive-services/Custom-Vision-Service/python-tutorial

support: https://github.com/Azure/azure-sdk-for-python/issues

Thank you.

I was also getting the same original issue (ModuleNotFoundError: No module named 'azure.cognitiveservices') for the spellcheck functions. Do NOT pip install azure . It installs all of the subpackages and I have a feeling there is an overlap between them that is causing issues.

I couldn't easily remove all the sub packages so I wiped my environment, started fresh, and this time only installed the pack I wanted (in this case pip install azure-cognitiveservices-language-spellcheck).

Now I am able to from azure.cognitiveservices.language.spellcheck import SpellCheckAPI without problem

If you suspect overlap, please report that on the azure-sdk-for-python repository so they can resolve it there.

But installing only the package you need is the right approach. Being able to install all of them at once is just for convenience.

Hello,
I'm having the same issue. How can I resolve this?
Thank you.

Traceback (most recent call last):
File "un.py", line 1, in
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
ImportError: cannot import name 'ImageSearchAPI' from 'azure.cognitiveservices.search.imagesearch' (C:\Users\jafra\OneDrive\Desktop\myvenv\lib\site-packages\azure\cognitiveservices\search\imagesearch__init__.py)

Was this page helpful?
0 / 5 - 0 ratings