[Python] Issues when importing modules on AWS AppRunner (Python 3.11)

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I'm relatively new to AWS AppRunner, and I'm trying to deploy a simple FastAPI endpoint to perform some tests. Here is the main.py file :

    from fastapi import FastAPI
    import uvicorn
    from pydantic import BaseModel
    import numpy as np

    app = FastAPI()

    class InputNumber(BaseModel):
    value: float

    @app.post("/sqrt")
    async def compute_sqrt(input_data: InputNumber):
    result = np.sqrt(input_data.value)
    return {"result": float(result)}

    if __name__ == '__main__':
    uvicorn.run(app, port=8080, host='0.0.0.0')


    With this code, I have of course a requirements.txt file :

    fastapi
    uvicorn[standard]
    numpy
    pydantic


    At first, I tried to deploy it with Python 3, and the following commands :

    • build command : pip install -r requirements.txt
    • start command : python main.py

    Everything worked perfectly fine, and I tried to deploy it with Python 3.11 with the following commands :

    • build command : pip3 install -r requirements.txt
    • start command : python3 main.py

    The build is working fine, but I'm getting an unexpected error when the deployment starts:

    ModuleNotFoundError: No module named 'fastapi'

    The build was correctly performed (every lib was downloaded as seen in the logs), and the same error occurs when adding a version to the libs in the requirements.txt file.

    I don't have docker

    Thanks in advance !

    Continue reading...

Compartilhe esta Página