最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Import Fitz with AWS Lambda : cannot import name '_extra' from partially initialized module 'py

programmeradmin1浏览0评论

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": []
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论