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:
- https://alexharv074.github.io/2018/08/18/creating-a-zip-file-for-an-aws-lambda-python-function.html
- https://dev.to/razcodes/how-to-create-a-lambda-using-python-with-dependencies-4846
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