[英]ModuleNotFoundError: No module named 'google.cloud.location'
We have an application that uses firestore.我们有一个使用 firestore 的应用程序。 It is running on Python 3.x on standard Google app engine.
它运行在标准谷歌应用引擎上的 Python 3.x 上。 The application was running fine, till this morning when we tried to run the new version.
该应用程序运行良好,直到今天早上我们尝试运行新版本时。 The deployment of the new version is executed without any error.
新版本的部署执行没有任何错误。 The requirement.txt is as follows -
requirement.txt 如下——
firebase_admin==3.0.0
sendgrid==6.9.3
google-auth==1.35.0
google-auth-httplib2==0.1.0
jinja2==3.0.3
MarkupSafe==2.0.1
pytz==2021.3
Flask==2.0.2
twilio==6.46.0
httplib2==0.20.2
requests==2.24.0
requests_toolbelt==0.9.1
google-cloud-tasks==2.7.1
google-cloud-logging==1.15.1
googleapis-common-protos==1.54.0
protobuf==3.20.1
We get the following error.我们收到以下错误。
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 55, in <module>
from google.cloud.location import locations_pb2 # type: ignore
ModuleNotFoundError: No module named 'google.cloud.location'
Please help.请帮忙。
Updated (9-24-2022) with the complete error output.已更新 (9-24-2022),包含完整错误 output。
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
super().init_process()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/srv/main.py", line 8, in <module>
from controllers import server, common, header
File "/srv/controllers/server.py", line 19, in <module>
from controllers import basehandler
File "/srv/controllers/basehandler.py", line 12, in <module>
from google.cloud import firestore
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
from google.cloud.firestore_v1 import __version__
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 36, in <module>
from google.cloud.firestore_v1.async_client import AsyncClient
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/async_client.py", line 45, in <module>
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/async_transaction.py", line 49, in <module>
from google.cloud.firestore_v1.client import Client
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/client.py", line 44, in <module>
from google.cloud.firestore_v1.services.firestore import client as firestore_client
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/__init__.py", line 16, in <module>
from .client import FirestoreClient
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 55, in <module>
from google.cloud.location import locations_pb2 # type: ignore
ModuleNotFoundError: No module named 'google.cloud.location'
It looks like Google made a mistake in setting requirements for one its Python packages.看起来谷歌在为其 Python 软件包设置要求时犯了一个错误。
If you create a new virtual environment, install with pip install -r
you should be able to recreate the error you are seeing in production.如果您创建一个新的虚拟环境,使用
pip install -r
安装,您应该能够重新创建您在生产中看到的错误。
To fix it, I would do pip list
on your local machine (in the environment that is still working) and add fixed versions of other installed google packages until it works.要修复它,我会在您的本地计算机上执行
pip list
(在仍在工作的环境中)并添加其他已安装的谷歌包的固定版本,直到它工作。
You can test by creating a new Python virtual environment, installing with pip install -r
and seeing if it works.您可以通过创建一个新的 Python 虚拟环境进行测试,使用
pip install -r
并查看它是否有效。
It is a tedious process unfortunately.不幸的是,这是一个乏味的过程。
I got this exact same error just now while trying to link a Python script to Firestore.我刚才在尝试将 Python 脚本链接到 Firestore 时遇到了这个完全相同的错误。 I don't know if this is a "correct" solution but I got my code to run and save data to my Firestore database after this doing this.
我不知道这是否是一个“正确”的解决方案,但在执行此操作后我让我的代码运行并将数据保存到我的 Firestore 数据库中。
In the error message, this line specifies the file where google.cloud.location is being imported:在错误消息中,此行指定了导入 google.cloud.location 的文件:
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 55, in <module>
If you open the client.py file and comment out the line 55 ("from google.cloud.location import locations_pb2 # type: ignore"), then run your code again, the next error message will show the other file where google.cloud.location is being imported.如果您打开 client.py 文件并注释掉第 55 行(“from google.cloud.location import locations_pb2 # type: ignore”),然后再次运行您的代码,下一条错误消息将显示 google.cloud 所在的其他文件.location 正在导入。 Repeat this process for all five files where this module is imported.
对导入此模块的所有五个文件重复此过程。 (client.py, base.py, grpc.py, grpc_asyncio.py, async_client.py)
(client.py, base.py, grpc.py, grpc_asyncio.py, async_client.py)
From searching through the code, I'm seeing that locations_pb2 (imported from google.cloud.location) is never used.通过搜索代码,我看到从未使用过 locations_pb2(从 google.cloud.location 导入)。 I suspect that commenting this out entirely won't affect the functionality of firebase_admin.
我怀疑将其完全注释掉不会影响 firebase_admin 的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.