Home > Software engineering >  AWS Lambda python Error: Runtime.ImportModuleError: Unable to import module 'app': cannot
AWS Lambda python Error: Runtime.ImportModuleError: Unable to import module 'app': cannot

Time:12-24

I just redeploy my AWS Lambda & accidentally face an issue:

[ERROR] 
Runtime.ImportModuleError: Unable to import module 'app': cannot import name 'operatorPrecedence' from 'pyparsing' 
(/opt/python/pyparsing/__init__.py)
(/var/task/pyparsing/__init__.py)

How do I solve this?

CodePudding user response:

I saw a release note that this feature was discontinued in version 3 of pyparsing:

operatorPrecedence synonym for infixNotation - convert to calling infix_notation

So you may be including a different version of pyparsing than you have been using previously--one that does not include the operatorPrecedence functionality, so double check what version of pyparsing you are including.

This Knowledge Center article outlines the most common issues:

You typically receive this error when your Lambda environment can't find the specified library in the Python code. This is because Lambda isn't prepackaged with all Python libraries.

To resolve this error, create a deployment package or Lambda layer that includes the libraries that you want to use in your Python code for Lambda.

Here's a couple other examples that don't use layers if you want to include the dependency in the code package directly instead:

CodePudding user response:

Basically, I fix this issue by following steps:

  • make virtualenv
  • manually add needed packages/library
  • prepare requirements.txt by python3 -m pip freeze > requirements.txt
  • deploy your code

Note:

  • After doing the above step, If you still facing the same issue,
  • Then used pyparsing==2.4.7 instead of pyparsing==3.0.6 OR updated version
  • Related