【问题标题】:Can not deploy Cloud Function with language_tool_python in Python 3.7 runtime无法在 Python 3.7 运行时中使用 language_tool_python 部署 Cloud Function
【发布时间】:2020-11-11 10:43:38
【问题描述】:

您如何使用 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?

【问题讨论】:

    标签: google-cloud-platform deployment google-cloud-functions languagetool


    【解决方案1】:

    documentation prerequisite 明确,需要 Python 3.7 和 Java 8.0+。

    而且,对于云函数,您不能拥有自定义运行时(至少目前还没有),因此您不能在同一个运行时环境中拥有 Java 和 Python。

    为此,我建议您使用Cloud Run。它与 Cloud Function 非常相似,但是由于您必须构建自己的容器,因此您可以根据需要自定义运行时环境。 要从一个切换到另一个,我wrote an article on this (my first one!)

    【讨论】:

      猜你喜欢
      • 2019-08-22
      • 2021-06-21
      • 2019-07-13
      • 2022-12-12
      • 2020-03-01
      • 2022-07-15
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      相关资源
      最近更新 更多