我运行了以下代码
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.abspath('resources/wakeupcat.jpg')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)我得到的错误如下
Traceback (most recent call last):
File "F:\coding\pythonfolder\main.py", line 4, in <module>
from google.cloud import vision
ModuleNotFoundError: No module named 'google'安装的库如下
pip install google-cloud-vision我是相当新的谷歌视觉api,所以也许有一点我错过了,请告诉我问题是什么,我尝试了pip安装--upgrade google-cloud-vision以及,但似乎不起作用,我的python版本是Python 3.10.0亲切地告诉我,如果我的问题中有任何问题或缺失的信息,谢谢!
发布于 2022-07-04 09:11:05
我很确定你把venv搞砸了,因为它对我很好。尝试使用PyCharm (如果您还没有使用)并安装一个venv,或者在项目文件夹中安装virtualenv并启动以下命令:
virtualenv venv
source venv/bin/activate
pip install google-cloud-vision
python your_file.py
deactivate最后一个是正确退出venv
https://stackoverflow.com/questions/72854194
复制相似问题