#๐Ÿ”’ FastAPI ModuleNotFound

19 messages ยท Page 1 of 1 (latest)

inland sorrel
#

can someone help me with some ModuleNotFoundError messages im getting when trying to compile my app? im sure im just missing something, but this is what i have:

Project structure is this:

src/
 |__ cmd/
      |__ util/
            |__ api/
                 |__app/
                      |__ models/
                            |__ models.py
                      |__ routers/
                            |__ routes.py
                      |__ main.py
                 |__ requirements.txt

Dockerfile:

FROM ubuntu:22.04 AS ingester-api

# download python pkgs
RUN apt-get update && apt install -y python3.11 python3-pip

WORKDIR /src

# copy all python files
COPY ./src/cmd/util/api /src/cmd/util/api
COPY ./src/cmd/util/api/requirements.txt /src/cmd/util/api

ENV PYTHONPATH=/src

RUN pip install -r /src/cmd/util/api/requirements.txt

# set working dir to go into fastapi app dir
WORKDIR /src/cmd/util/api/app

EXPOSE 5000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000", "--reload"]

Imports in main.py:

from fastapi import FastAPI
from routers.routes import redis_router

Error:

  File "/src/cmd/util/api/app/main.py", line 4, in <module>
    from routers.routes import redis_router
zenith jungleBOT
#

@inland sorrel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

inland sorrel
lapis aurora
inland sorrel
lapis aurora
#

Yes

inland sorrel
lapis aurora
#

Also your ENV PYTHONPATH=/src is redundant

inland sorrel
lapis aurora
#

Hmm that should work

#

Try getting rid of the PYTHONPATH env set

#

Also you're using the sync Redis API with the async def

#

You need to either switch to sync defs or the async Redis API

inland sorrel
lapis aurora
inland sorrel
zenith jungleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.