I had this problem recently - my issue was that the COPY . . command was accidentally overwriting dependencies by copying over the .venv folder.
COPY . .
.venv
The solution was to add .venv to a .dockerignore file so it doesn't get copied.
.dockerignore