AWS Lambda nltk error: No module named 'regex._regex'
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:
- python3.9 -m pip install nltk==3.6.3 -t <<lambda_function>>/python
- 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.
- Language
- English
asked 3 years ago4.4K views
- Newest
- Most votes
- Most comments
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 :
- rePost-User-21017193 years ago
It has worked. The solution is given in the link you shared : https://github.com/nltk/nltk/issues/2870 Adding regex>=2021.8.3 in the requirements file. Thanks
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
Relevant content
asked 3 years ago
asked 3 years ago
