简体   繁体   English

部署后我的应用报告 - 无法从“google.cloud”导入名称“vision”

[英]Once deployed my app reports - Cannot import name 'vision' from 'google.cloud'

I am working on a Google App and have an issue when I deploy it.我正在开发一个 Google 应用程序,但在部署它时遇到了问题。 The project contains two services website and worker.该项目包含两个服务网站和工作人员。 The website acts as a front page and the worker is run through a cron and has its page hit every 5 minutes.该网站充当首页,工作人员通过 cron 运行,每 5 分钟访问一次页面。

The issue I'm having is that when running them locally both services run fine.我遇到的问题是,在本地运行它们时,两个服务都运行良好。 Once I deploy with gcloud the application returns an error in the Logs Console.使用 gcloud 部署后,应用程序会在日志控制台中返回错误。

The error is: ImportError: cannot import name 'vision' from 'google.cloud' (unknown location)错误是: ImportError: cannot import name 'vision' from 'google.cloud' (unknown location)

It is the worker service that is not working.工作人员服务不起作用。 It's requirements.txt reads这是 requirements.txt 读取

Flask~=1.1.2
google-api-core==1.22.4
google-auth==1.23.0
google-cloud-core==1.4.3
google-cloud-datastore==2.0.0
google-cloud-logging==2.0.0
google-cloud-storage==1.33.0
google-cloud-vision==2.0.0
google-crc32c==1.0.0
google-resumable-media==1.1.0
requests==2.25.0

The imports for the worker are工人的进口是

import os
import logging
import google.cloud.logging
import google.oauth2.id_token

from flask import Flask, render_template, request
from google.auth.transport import requests
from google.cloud import datastore
from google.cloud import vision

The full error on the Logs explorer is日志资源管理器上的完整错误是

Traceback (most recent call last):
  File "/layers/google.python.webserver/gunicorn/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/layers/google.python.webserver/gunicorn/gunicorn/workers/gthread.py", line 92, in init_process
    super().init_process()
  File "/layers/google.python.webserver/gunicorn/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/layers/google.python.webserver/gunicorn/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/layers/google.python.webserver/gunicorn/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/layers/google.python.webserver/gunicorn/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/layers/google.python.webserver/gunicorn/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/layers/google.python.webserver/gunicorn/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/opt/python3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/srv/main.py", line 9, in <module>
    from google.cloud import vision
ImportError: cannot import name 'vision' from 'google.cloud' (unknown location)

I've tried rearranging the imports as I read that there could be some namespace issues but that didn't fix it我已经尝试重新安排导入,因为我读到可能存在一些命名空间问题,但这并没有解决它

The issue seemed to be caused by the order of the components in the requirements file, similar to this issue .该问题似乎是由需求文件中组件的顺序引起的,类似于 此问题 The solution is to explicitly include the grpcio module in the requirements.txt file, eg :解决方案是在requirements.txt文件中明确包含grpcio模块,例如:

Flask~=1.1.2
google-api-core==1.22.4
google-auth==1.23.0
google-cloud-core==1.4.3
google-cloud-datastore==2.0.0
google-cloud-logging==2.0.0
google-cloud-storage==1.33.0
google-cloud-vision==2.0.0
google-crc32c==1.0.0
google-resumable-media==1.1.0
requests==2.25.0
grpcio==1.34.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Function - ImportError:无法从“google.cloud”(未知位置)导入名称“pubsub” - Google Cloud Function - ImportError: cannot import name 'pubsub' from 'google.cloud' (unknown location) Cloud Function 无法从“google.cloud”(未知位置)导入名称“storage” - Cloud Function cannot import name 'storage' from 'google.cloud' (unknown location) 从 google.cloud 导入 monitoring_v3 导入错误:无法导入名称 monitoring_v3 - from google.cloud import monitoring_v3 ImportError: cannot import name monitoring_v3 从 google.cloud 导入数据存储给出“ImportError:无法导入名称“collections_abc”” - from google.cloud import datastore gives 'ImportError: cannot import name 'collections_abc'' ImportError:无法从“google.cloud”(未知位置)导入名称“speech” - ImportError: cannot import name 'speech' from 'google.cloud' (unknown location) 导入错误:无法从“google.cloud”(未知位置)导入名称“pubsub_v1” - ImportError: cannot import name 'pubsub_v1' from 'google.cloud' (unknown location) ImportError:无法从“google.cloud”导入名称“tasks_v2” - ImportError: cannot import name 'tasks_v2' from 'google.cloud' 导入错误:无法从“google.cloud”(未知位置)导入名称“texttospeech” - ImportError: cannot import name 'texttospeech' from 'google.cloud' (unknown location) 导入错误:无法从“google.cloud”(未知位置)导入名称“bigquery_storage_v1beta1” - ImportError: cannot import name 'bigquery_storage_v1beta1' from 'google.cloud' (unknown location) ImportError:无法从“google.cloud”(未知位置)导入名称“bigquery” - ImportError: cannot import name 'bigquery' from 'google.cloud' (unknown location)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM