AWS Lambda出现nltk错误:未找到模块‘regex._regex’。

0

【以下的问题经过翻译处理】 您好,我正在使用Python 3.9和AWS Lambda。在lambda函数中,我使用nltk模块进行一些操作。 要创建层,我已执行以下操作:

  1. 执行:python3.9 -m pip install nltk==3.6.3 -t <<lambda_function>>/python
  2. 在template.yml中创建一个层,如下所示:
    XXXNLTKLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      ContentUri: <<lambda_function>>/python/
      LayerName: nltk-layer
      CompatibleRuntimes:
        - python3.9
      CompatibleArchitectures:
        - x86_64
    Metadata:
      BuildMethod: python3.9 

我在发布后的Sam本地调用和AWS控制台中进行测试,但遇到以下错误: {"errorMessage": "Unable to import module 'app': No module named 'regex._regex'", "errorType": "Runtime.ImportModuleError"

我无法使用Google搜索出的建议解决此问题。我尝试使用最新版本的nltk包,但出现相同的问题。如果有人遇到过这个问题,请为我提供建议。

1回答
0

【以下的回答经过翻译处理】 你好,感谢您的查询。

由于出现“ No module named 'regex._regex’”错误,通常是因为未安装“regex”模块。为此,您需要安装“regex”模块。您可以尝试使用以下命令安装“regex”模块。

pip install regex 

或者

pip install -U regex

希望安装“regex”包后,您不会遇到该错误。如果问题仍然存在,请使用以下链接打开支持案例向AWS寻求帮助:https://console.aws.amazon.com/support/home#/case/create

参考资料:

  1. https://pypi.org/project/regex/
  2. https://github.com/nltk/nltk/issues/2870
  3. https://stackoverflow.com/questions/64498145/aws-lambda-python-unable-to-import-module-lambda-function-no-module-named-r
profile picture
エキスパート
回答済み 8ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ