AWS Lambda nltk error: No module named 'regex._regex'

0

Hi, I'm using python 3.9 with AWS Lambda. In the lambda I'm using nltk module for few operations. For creating the layer, I've done the following:

  1. python3.9 -m pip install nltk==3.6.3 -t <<lambda_function>>/python
  2. Created a layer in 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 

I'm testing both in Sam local invoke and AWS console after publishing, getting the following error: {"errorMessage": "Unable to import module 'app': No module named 'regex._regex'", "errorType": "Runtime.ImportModuleError"

I'm not able to get a workaround for this using existing google suggestions. I tried with latest version of nltk package but it's giving me the same issue. If someone has encountered this please suggest me a way.

2 Respuestas
1
Respuesta aceptada

Hello, Thank you for your query.

As you are getting error as ‘ No module named 'regex._regex’. This error generally occurs when the ‘regex’ module is not installed. For this you need to install ‘regex’ module. You can try the following command for installing the ‘regex’ module.

pip install regex 

Or

pip install -U regex

Hope that after installing the regex package you will not encounter with the error. If problem still persists please open a support case with AWS using the following link: https://console.aws.amazon.com/support/home#/case/create

References :

  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
AWS
Aamir
respondido hace un año
0

Which version of the regex should I install? Please provide me the command. I tried regex>=2021.8.3 and regex-2023.8.8 but it didn't worked. I am still getting the AWS Lambda nltk error: No module named 'regex._regex'.

respondido hace 9 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas