如何解决 Google 云功能上的"No module named 'frontend'"错误消息



我试图用Python 3.9部署一个云函数,但当我运行时

gcloud functions deploy my_function --project my_project --runtime python39 --trigger-resource bucket_name --trigger-event google.storage.object.finalize

部署失败,出现以下错误:

Traceback (most recent call last):
File "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>
sys.exit(_cli())
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/_cli.py", line 37, in _cli
app = create_app(target, source, signature_type)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 288, in create_app
spec.loader.exec_module(source_module)
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/workspace/main.py", line 2, in <module>
import fitz
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/fitz/__init__.py", line 1, in <module>
from frontend import *
ModuleNotFoundError: No module named 'frontend'

我在这里发现了一个类似的问题,但我如何在云功能中安装PyMuPDF?它不应该通过requirements.txt文件自行安装吗?

这是我的目录结构:

── folder
├── main.py
├── requirements.txt

这是我的main.py:

import numpy as np
import fitz
import os
from google.cloud import storage
def my_function()
do stuff with fitz

这是我的requirements.txt文件:

cachetools==4.2.4
certifi==2021.10.8
charset-normalizer==2.0.9
ci-info==0.2.0
click==8.0.3
configobj==5.0.6
configparser==5.2.0
etelemetry==0.2.2
filelock==3.4.0
fitz==0.0.1.dev2
future==0.18.2
google-api-core==2.3.0
google-auth==2.3.3
google-cloud-core==2.2.1
google-cloud-storage==1.43.0
google-crc32c==1.3.0
google-resumable-media==2.1.0
googleapis-common-protos==1.54.0
httplib2==0.20.2
idna==3.3
isodate==0.6.0
lxml==4.6.4
networkx==2.6.3
nibabel==3.2.1
nipype==1.7.0
numpy==1.21.4
packaging==21.3
pandas==1.3.4
pathlib==1.0.1
protobuf==3.19.1
prov==2.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pydot==1.4.2
PyMuPDF==1.19.2
pyparsing==3.0.6
python-dateutil==2.8.2
pytz==2021.3
pyxnat==1.4
rdflib==6.0.2
requests==2.26.0
rsa==4.8
scipy==1.7.3
simplejson==3.17.6
six==1.16.0
traits==6.3.2
urllib3==1.26.7
joblib~=1.1.0

我通过pip freeze> requirements.txt创建了此列表

在您链接的线程中,有几个解决方案,其中一个有趣的解决方案似乎是名为fitz的包与PyMuPDF冲突,因为它们在脚本中都使用相同的顶端名称(即fitz(。我看到这两个库都在您的requirements.txt中,所以这可能是导致此错误的原因。我测试了在Cloud Function中添加这两个库,并收到了相同的错误,在从文件中删除fitz 0.0.1.dev2并仅使用PyMuPDF后,该错误得到了解决。

你可以从这个GitHub问题中看到这种行为的另一个例子。

相关内容

  • 没有找到相关文章

最新更新