您如何使用 Google Cloud Function 中的语言工具?我正在尝试使用运行时 Python 3.7 在 GCP Cloud Function 中进行部署。我可以使用安装了 java 的本地虚拟环境来使用该库。
但是当我尝试在 Cloud Function 中部署它时,我收到ModuleNotFoundError: No java install detected。请安装 java 以使用 language-tool-python。
我在云函数中使用 language_tool_python 库
# install and import for grammar accuracy
import language_tool_python
tool = language_tool_python.LanguageTool('en-IN')
matches = tool.check(input_string)
在 requirements.txt 我们有 -
language-tool-python==2.4.5
我收到以下错误消息 -
Function failed on loading user code. Error message: 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/worker_v2.py", line 359, in check_or_load_user_function _function_handler.load_user_function()
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py",
line 236, in load_user_function spec.loader.exec_module(main_module) 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 10, in <module> from libraries.unknown_word import word_meaning File "/user_code/libraries/unknown_word.py", line 18, in <module> tool = language_tool_python.LanguageTool('en-IN')
File "/env/local/lib/python3.7/site-packages/language_tool_python/server.py", line 46, in __init__ self._start_server_on_free_port() File "/env/local/lib/python3.7/site-packages/language_tool_python/server.py", line 183, in _start_server_on_free_port self._start_local_server()
File "/env/local/lib/python3.7/site-packages/language_tool_python/server.py", line 193, in _start_local_server download_lt() File "/env/local/lib/python3.7/site-packages/language_tool_python/download_lt.py", line 144, in download_lt confirm_java_compatibility()
File "/env/local/lib/python3.7/site-packages/language_tool_python/download_lt.py", line 75, in confirm_java_compatibility
raise ModuleNotFoundError('No java install detected. Please install java to use language-tool-python.')
ModuleNotFoundError: No java install detected. Please install java to use language-tool-python.
谁能提供一个解决方案,如何从无服务器功能中使用 LanguageTool?
我们如何在 Cloud Function 中拥有 Java 环境以及 Python 3.7?