VOOZH about

URL: https://repost.aws/questions/QUIgt6iQ3aTO6fdyDNnNoMSg/aws-lambda-nltk-error-no-module-named-regex-regex

⇱ AWS Lambda nltk error: No module named 'regex._regex' | AWS re:Post


Skip to content

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 Answers
  • Newest
  • Most votes
  • Most comments
1
Accepted Answer

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

answered 3 years ago

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'.

answered 3 years ago