【问题标题】:Python ModuleNotFoundError: No module named 'azure.cognitiveservices'Python ModuleNotFoundError:没有名为“azure.cognitiveservices”的模块
【发布时间】:2020-11-20 08:02:51
【问题描述】:

我正在按照 Microsoft (https://docs.microsoft.com/nl-nl/azure/cognitive-services/Computer-vision/quickstarts-sdk/client-library?pivots=programming-language-python) 的教程使用认知服务。我在这里使用 Visual Code 并使用命令行使用 pip 安装 Azure:

pip install azure-cognitiveservices-vision-customvision

我使用第一个和平的代码(见下面的代码)并尝试运行代码。但它返回以下错误:

(myvenv) PS C:\Users\erikh\OneDrive\Documenten\Git\Python Testlab> & "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/myvenv/Scripts/python.exe" "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/readText.py"
Traceback (most recent call last):
  File "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/readText.py", line 1, in <module>
    from azure.cognitiveservices.vision.computervision import ComputerVisionClient
ModuleNotFoundError: No module named 'azure.cognitiveservices'

这是我尝试执行的代码:

from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials

from array import array
import os
from PIL import Image
import sys
import time

# Add your Computer Vision subscription key to your environment variables.
if 'COMPUTER_VISION_SUBSCRIPTION_KEY' in os.environ:
    subscription_key = os.environ['COMPUTER_VISION_SUBSCRIPTION_KEY']
else:
    print("\nSet the COMPUTER_VISION_SUBSCRIPTION_KEY environment variable.\n**Restart your shell or IDE for changes to take effect.**")
    sys.exit()
# Add your Computer Vision endpoint to your environment variables.
if 'COMPUTER_VISION_ENDPOINT' in os.environ:
    endpoint = os.environ['COMPUTER_VISION_ENDPOINT']
else:
    print("\nSet the COMPUTER_VISION_ENDPOINT environment variable.\n**Restart your shell or IDE for changes to take effect.**")
    sys.exit()

【问题讨论】:

    标签: python python-3.x azure azure-cognitive-services


    【解决方案1】:

    我可以重现你的问题,你安装了错误的包,应该是azure-cognitiveservices-vision-computervision而不是azure-cognitiveservices-vision-customvision

    运行下面的行,然后它会正常工作。

    pip install azure-cognitiveservices-vision-computervision
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 2021-06-03
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多