pydantic / pydantic-core

Core validation logic for pydantic written in rust
MIT License
1.4k stars 232 forks source link

Lambda Import Error - No module named 'pydantic_core._pydantic_core' #1409

Closed dinopanagos closed 1 month ago

dinopanagos commented 1 month ago

Getting this error nonstop for days after packing my python zip for lambda. in my req text these dont cover the pydantic error langchain_openai
langchain_community langchain_core langchain

Here are the 3 things ive tried.

Have tried using docker (dockerfile below) and using a Lambda layer -> https://api.klayers.cloud/api/v2/p3.11/layers/latest/us-east-1/json with no luck. (note i have also tried amazonlinux image as well)

FROM python:3.11-slim
RUN apt-get update && apt-get install -y zip && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . .
RUN python3 -m pip install --no-cache-dir -r requirements.txt -t .
RUN zip -r lambda.zip .
CMD cp lambda.zip /host_mounted_volume
  1. for my requirements.txt i have tried

    pydantic==2.5.3
    pydantic_core==2.14.6

    with no luck either.

  2. I have also tried creating a custom layer and zipped with : pip install --platform manylinux_2_17_x86_64 --only-binary=:all: pydantic-core==2.20.1 -t python

dinopanagos commented 1 month ago

note: i get no errors on my local in pycharm with anything pydantic

sydney-runkle commented 1 month ago

Hi! You should be able to resolve this with the help of this integration guide: https://docs.pydantic.dev/latest/integrations/aws_lambda/

Also, see details on this issue: https://docs.pydantic.dev/latest/integrations/aws_lambda/#no-package-metadata-was-found-for-email-validator