Python Azure功能“;ModuleNotFoundError“;用于本地脚本

Python Azure功能“;ModuleNotFoundError“;用于本地脚本,python,azure,azure-functions,Python,Azure,Azure Functions,我有以下文件夹结构: Monday |-- __init__.py |-- api.py |-- db.py |-- exceptions.py |-- function.json |-- main.py `-- process_data.py 在mymain.py中,我从process\u data.py导入方法。当我运行func start启动Azure函数时,我得到: (venv) ➜ monday git:(main) ✗ func start Found Python versio

我有以下文件夹结构:

Monday
|-- __init__.py
|-- api.py
|-- db.py
|-- exceptions.py
|-- function.json
|-- main.py
`-- process_data.py
在my
main.py
中,我从
process\u data.py
导入方法。当我运行
func start
启动Azure函数时,我得到:

(venv) ➜  monday git:(main) ✗ func start
Found Python version 3.8.5 (python3).
Azure Functions Core Tools (3.0.2931 Commit hash: d552c6741a37422684f0efab41d541ebad2b2bd2)
Function Runtime Version: 3.0.14492.0

Functions:

        monday: timerTrigger

For detailed output, run func with --verbose flag.
[2020-11-02T00:56:08.423] Worker process started and initialized.
[2020-11-02T00:56:08.975] Worker failed to function id f73b3d07-44a3-4f64-be74-617bc6fede70.
[2020-11-02T00:56:08.976] Result: Failure
[2020-11-02T00:56:08.976] Exception: ModuleNotFoundError: No module named 'monday'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound
[2020-11-02T00:56:08.976] Stack:   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2931/workers/python/3.8/OSX/X64/azure_functions_worker/dispatcher.py", line 262, in _handle__function_load_request
[2020-11-02T00:56:08.976]     func = loader.load_function(
[2020-11-02T00:56:08.976]   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2931/workers/python/3.8/OSX/X64/azure_functions_worker/utils/wrappers.py", line 34, in call
[2020-11-02T00:56:08.976]     raise extend_exception_message(e, message)
[2020-11-02T00:56:08.976]   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2931/workers/python/3.8/OSX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call
[2020-11-02T00:56:08.976]     return func(*args, **kwargs)
[2020-11-02T00:56:08.976]   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2931/workers/python/3.8/OSX/X64/azure_functions_worker/loader.py", line 76, in load_function
[2020-11-02T00:56:08.976]     mod = importlib.import_module(fullmodname)
[2020-11-02T00:56:08.976]   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
[2020-11-02T00:56:08.976]     return _bootstrap._gcd_import(name[level:], package, level)
[2020-11-02T00:56:08.976]   File "/Users/en/Workspace/zypp/monday/monday/process_data.py", line 3, in <module>
[2020-11-02T00:56:08.976]     from monday.api import request_data
[2020-11-02T00:56:08.976] .
my
function.json的内容:

{
“脚本文件”:“main.py”,
“绑定”:[
{
“名称”:“计时器”,
“类型”:“timerTrigger”,
“方向”:“在”,
“附表”:“0*/5****”
}
]
}

注意:代码本身运行良好。

下面是我这边的代码,它运行良好:

main.py

import logging

import azure.functions as func
from .process_data import funcname1, funcname2

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    funcname1()
    funcname2()
    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )
def funcname1():
    """
    docstring
    """
    print('This is funcname1')
    pass

def funcname2():
    """
    docstring
    """
    print('This is funcname2')
    pass
处理数据.py

import logging

import azure.functions as func
from .process_data import funcname1, funcname2

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    funcname1()
    funcname2()
    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )
def funcname1():
    """
    docstring
    """
    print('This is funcname1')
    pass

def funcname2():
    """
    docstring
    """
    print('This is funcname2')
    pass
function.json

{
  "scriptFile": "main.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}
这是我这边的结构:

它工作得很好:


由于这两个模块位于同一个目录中,因此您可以从中说
。导入api
这就是解决方案吗?我想运行
export\u-to\u-azure
create\u-dataframe
from
process\u-data
。看起来我做得很正确,请参阅我的编辑,我添加了
main.py
尝试使用
从process\u data import导出到\u azure,创建\u dataframe
。尝试了,没有成功,相同的错误@DorisLv
来自。process\u data import api
,这应该可以工作<代码>
表示当前文件夹。我会在有时间时尝试此操作。谢谢,在我使用Azure CLI和我的终端之前,当我在VS代码中构建一切时,它工作正常。我不知道为什么那不起作用。