发布到 Azure 后无法执行 Azure App Function (Python)。 'No module named <n>'。在本地工作
Failed executing Azure App Function (Python) after publishing to Azure. 'No module named <n>'. Works locally
我创建了一个 python 函数作为 Azure 应用程序函数。它在我的本地机器上运行良好,但是在成功发布后执行时失败且没有描述性错误。
最初,它因 500 内部服务器错误而失败,原因是:
Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'
Stack: File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 218, in _handle__function_load_request
func_request.metadata.entry_point)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, in load_function
mod = importlib.import_module(fullmodname)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/generateGraph/__init__.py", line 2, in <module>
import pandas as pd
我以为这是我没有使用 --build-native-deps 开关发布。所以我用这个开关重新发布:(.env) C:\Temp\python_function>func azure functionapp publish httpGenGraph --build-native-deps
发布成功。现在,当我执行 Http 触发器时,我再次遇到同样的错误。有什么我想念的吗?我是 Python 的新手,所以可能不了解包装要求或其他内容。该功能在我的本地虚拟 python 环境中确实有效。
想通了。我需要将 pip freeze 的输出通过管道传输到 requirements.txt 文件。这允许在发布时正确引用包。
供参考:
(.env) C:\Temp\python_function>pip freeze > requirements.txt
然后:
(.env) C:\Temp\python_function>func azure functionapp publish httpGenGraph --build-native-deps
我创建了一个 python 函数作为 Azure 应用程序函数。它在我的本地机器上运行良好,但是在成功发布后执行时失败且没有描述性错误。
最初,它因 500 内部服务器错误而失败,原因是:
Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'
Stack: File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 218, in _handle__function_load_request
func_request.metadata.entry_point)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, in load_function
mod = importlib.import_module(fullmodname)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/generateGraph/__init__.py", line 2, in <module>
import pandas as pd
我以为这是我没有使用 --build-native-deps 开关发布。所以我用这个开关重新发布:(.env) C:\Temp\python_function>func azure functionapp publish httpGenGraph --build-native-deps
发布成功。现在,当我执行 Http 触发器时,我再次遇到同样的错误。有什么我想念的吗?我是 Python 的新手,所以可能不了解包装要求或其他内容。该功能在我的本地虚拟 python 环境中确实有效。
想通了。我需要将 pip freeze 的输出通过管道传输到 requirements.txt 文件。这允许在发布时正确引用包。
供参考:
(.env) C:\Temp\python_function>pip freeze > requirements.txt
然后:
(.env) C:\Temp\python_function>func azure functionapp publish httpGenGraph --build-native-deps