我正在从源存储库部署Google Cloud功能。只要我在main.py
中没有对存储库中用户定义的任何函数(即package
或package2
下方的main.py
之外。
.
├── package
| ├── __init__.py
| ├── main.py
| ├── requirements.txt
| ├── script1.py
| └── script2.py
├── package2
| ├── __init__.py
| ├── script3.py
| └── script4.py
└── ...
我最近有2个关于此功能部署here和here的堆栈溢出问题。他们共同为我提供了一个解决方案,其中main.py
和requirements.txt
位于一个程序包中,我以该程序包为源部署了Google Cloud Function。现在的问题是,我需要能够访问其他包/脚本中的函数/脚本。如果我在from package.script1 import foo
中包含类似main.py
的语句,则在部署函数时会收到类似以下的错误:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function load error: Code in file main.py can't be loaded.
Did you list all required modules in requirements.txt?
Detailed stack trace: Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/wo
rker.py", line 211, in check_or_load_user_function
_function_handler.load_user_function()
File "/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/wo
rker.py", line 140, in load_user_function
spec.loader.exec_module(main)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/user_code/main.py", line 4, in <module>
from package.script1 import foo
ModuleNotFoundError: No module named 'package'
我目前正在使用以下google函数deploy语句来部署此函数:
gcloud functions deploy NAME --source https://source.developers.google.com/projects/PROJECT_ID/repos/REPOSITORY_ID/moveable-aliases/BRANCH_NAME/paths/package/ --trigger-topic TOPIC
由于this stack overflow question中的问题,无法将main.py
和requirements.txt
移回根目录。
我需要一种在gcloud functions deploy ...
语句中导入用户定义的包/函数的方法。我的main.py
使用了package.script1.py
,package.script2.py
,package2.script3.py
和package2.script4.py
中的函数。如何做到这一点?
每个软件包(__init__.py
和package
)中确实都有package2
个文件,但它们目前为空白/空。
我尝试了以下gcloud deploy...
选项:
main.py
和requirements.txt
(而不是上面/最初显示的配置)中:
gcloud functions deploy NAME --source https://source.developers.google.com/projects/PROJECT_ID/repos/REPOSITORY_ID/moveable-aliases/BRANCH --trigger-topic TOPIC
这会产生以下错误:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function load error: File main.py that is expected to define function doesn't exist
为了明确地将根目录称为源,我还尝试了使用与#1相同的文件配置
gcloud functions deploy NAME --source https://source.developers.google.com/projects/PROJECT_ID/repos/REPOSITORY_ID/moveable-aliases/BRANCH/paths/ --trigger-topic TOPIC
它给了我与#1相同的错误:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function load error: File main.py that is expected to define function doesn't exist
在此问题中使用原始文件结构(在main.py
中使用requirements.txt
和package
),我已经尝试了上面提供的deploy语句。它解决了main.py
找不到的问题,但是给了我上面上面原始问题所述的错误
我还应该尝试什么?
答案 0 :(得分:0)
您应该像这样构建应用程序:
RecordSource
然后在Forms!frmQASingleView.RecordSource = "qQATeam"
DoCmd.OpenForm FormName:="frmQASingleView" View:=acNormal, WindowMode:=acWindowNormal
中,您可以执行以下操作:
.
├── main.py
├── package
│ ├── __init__.py
│ ├── script1.py
│ └── script2.py
├── package2
│ ├── __init__.py
│ ├── script3.py
│ └── script4.py
└── requirements.txt