-
Hi team, FROM ubuntu:22.04 AS build-parent
RUN sudo -H -E pip3 install --use-deprecated=legacy-resolver -r /requirements.txt
################################################
FROM google-gcr.artifactory.cicd.dc/distroless/python3-debian12 AS runtime
COPY --from=build-parent /app /app
COPY --from=build-parent /usr/local/lib/python3.9/dist-packages /usr/local/lib/python3.11/dist-packages
WORKDIR /app
ENTRYPOINT ["python3", "/app/entrypoint.py"] Basically I am trying to copy the library dependencies from build-parent container (consisting python3.9) to distroless container (consisting python3.11). However, I am facing an issue while trying to import Memray. I am getting this following error: File "/home/dsci/classifier-api/app/core/middleware.py", line 13, in <module>
import memray
File "/usr/local/lib/python3.11/dist-packages/memray/__init__.py", line 2, in <module>
from ._memray import AllocationRecord
ImportError: cannot import name 'AllocationRecord' from 'memray._memray' (unknown location) Can you please help in realising what might be the issue and how to resolve it? The challenge I'm facing is, as the final image is a distroless container I cannot use any shell commands like pip install directly to install dependencies. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That's the problem. A Python 3.11 interpreter can't use libraries that were compiled for Python 3.9. You'd need to use the same version of Python in both environments. Or, alternatively, you could try just downloading a Python 3.11 Memray wheel like https://files.pythonhosted.org/packages/d6/57/83cb83cc3412014f180c90a1c8800e264e03fefc071a523d7e91126b23b4/memray-1.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl and unzipping it with |
Beta Was this translation helpful? Give feedback.
That's the problem. A Python 3.11 interpreter can't use libraries that were compiled for Python 3.9. You'd need to use the same version of Python in both environments. Or, alternatively, you could try just downloading a Python 3.11 Memray wheel like https://files.pythonhosted.org/packages/d6/57/83cb83cc3412014f180c90a1c8800e264e03fefc071a523d7e91126b23b4/memray-1.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl and unzipping it with
unzip
, and then copying the unzipped contents directly into thedist-packages
folder. But if you di…