I want to import fitz on AWS lambda
Following these AWS instructions, I have:
- pip installed PymuPdf
pip install --target ./package pymupdf
- added lambda_function.py to package folder
- Zipped the content of package: PyMuPdf pacakges & the lambda_function.py
- Uploaded my_deployment_package.zip
- Tested the lambda
(note: To verify process up until here was correct, I also pip installed PyPDF2
to import this in the lambda)
This is the .ZIP folder content:
my_deployment_package.zip/
|
├── bin/ #fitz pip install
|
├── fitz/ #from fitz pip install
|
├── pymupdf/ #from fitz pip install
|
├── pymupdf-1.25.2.dist-info/ #from fitz pip install
|
├── PyPDF2/ #from PyPDF2 pip install
|
├── pypdf2-3.0.1.dist-info/ #from PyPDF2 pip install
|
└── lambda_function.py #my lambda function
After upload I tested the following lambda:
from PyPDF2 import PdfReader # importing this to verify .zip--> upload method correct
import fitz #target package
def lambda_handler(event, context):
# Print the event (input to the Lambda function)
print("Received event:", event)
# Return a simple response
return {
'statusCode': 200,
'body': 'Hello from Lambda!'
}
I get the following error:
{
"errorMessage": "Unable to import module 'lambda_function': cannot import name '_extra' from partially initialized module 'pymupdf' (most likely due to a circular import) (/var/task/pymupdf/__init__.py)",
"errorType": "Runtime.ImportModuleError",
"requestId": "",
"stackTrace": []
}