语言\u工具\u python类型错误:无法pickle\u thread.lock对象

2024-04-23 16:26:08 发布

您现在位置:Python中文网/ 问答频道 /正文

正在尝试pickle language_tool_python.language_tool_python模块的language_tool('en-US')。 如何修复以下问题

import language_tool_python
import pickle
tool = language_tool_python.LanguageTool('en-US')

with open("lang_tool_pickle", "wb") as file:
    pickle.dump(tool, file)

这会产生以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-27-caf8effcda8a> in <module>()
      1 with open("lang_tool_pickle", "wb") as file:
----> 2     pickle.dump(tool, file)

TypeError: can't pickle _thread.lock objects