0

I have created a fastapi and tested it locally.

I created an Lambda function and uploaded the API throw it. While I am testing the function I am getting the error:

"No module named 'pydantic_core._pydantic_core'"

My runtime is python 3.10.0. I added this pydantic_core on my requirment.txt but same result.

Can anyone help me?

The error comes while testing the Lambda function on AWS stack.

1

2 Answers 2

0

These modules are usually not available on lambda, in this case you need to download the module file, unzip it and put it in the zip file that you will upload to lambda.

https://pypi.org/project/pydantic-core/#files

    my_deployment_package.zip
    |- pydantic-core
    |  |-xxx.py
    |  |-yyyy
    |  |-docsz
    ...
    |- lambda_function.py

See more at: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-create-dependencies

Sign up to request clarification or add additional context in comments.

3 Comments

I have already added layer.zip file on my lambda. under which pydantic_core package is there. still the same problem. most probaly, there is some versioning problem.
I think you should put module folder in the root
there was some problem on pydantic 2.0 package i think. i just downgrade my fastapi to 0.90.0 and pydantic to pydantic 1.0..it is working now
0

pip install pydantic==2.4.2

By installing the pydantic version 2.4.2 described in openai github requirement (https://github.com/openai/openai-python/blob/main/requirements.lock),

I could pass the "No module named 'pydantic_core._pydantic_core'" error. However now I am stuck with a new error which is

"'StrictVersion' object has no attribute 'startswith'"

It seems the python in AWS is not compatible with the pydantic I provided. Still stuck here. Sigh...

I will report back if I have any progress.

1 Comment

Did you have any progress?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.