Python ModuleNotFoundError: No module named 'azure.cognitiveservices'
Python ModuleNotFoundError: No module named 'azure.cognitiveservices'
我正在按照 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
我使用第一个和平代码(见下面的代码)并尝试运行代码。但它 returns 出现以下错误:
(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()
我可以重现你的问题,你安装了错误的包,应该是 azure-cognitiveservices-vision-computervision
而不是 azure-cognitiveservices-vision-customvision
。
运行下面一行,就可以正常工作了。
pip install azure-cognitiveservices-vision-computervision
我正在按照 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
我使用第一个和平代码(见下面的代码)并尝试运行代码。但它 returns 出现以下错误:
(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()
我可以重现你的问题,你安装了错误的包,应该是 azure-cognitiveservices-vision-computervision
而不是 azure-cognitiveservices-vision-customvision
。
运行下面一行,就可以正常工作了。
pip install azure-cognitiveservices-vision-computervision