keithrozario / Klayers

Python Packages as AWS Lambda Layers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] PyMuPDF error: Unable to import module 'lambda': cannot import name '_fitz' from partially initialized module 'fitz' (most likely due to a circular import)

Ricardomol opened this issue · comments

Describe the bug
Disclaimer. I'm not sure if this is a bug or I am doing something wrong.
I generate the zip file for the latest PyMuPDF version and upload it to AWS as a Layer. But it doesn't work, I get this error message whatever I try:

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda': cannot import name '_fitz' from partially initialized module 'fitz' (most likely due to a circular import) (/var/task/fitz/__init__.py)

Layer Version ARN:
arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-PyMUPDF:30

Framework:
Console.

Additional context
Add any other context about the problem here.

I'm able to get the following code working by directly using the layer:

import json
import fitz

def lambda_handler(event, context):
    print(fitz.__doc__)
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Not sure why yours isn't working.

Thanks for taking a look at it @keithrozario

I think my code is fine since it works with Python 3.6 (amazonlinux). The problem comes when trying to update to Python 3.8 and therefore having to use amazonlinux2.

In this PyMuPDF issue, several other users are reporting the same problem, even after using your layer. I'm pretty confused about what I might be missing.