Hi, I am getting the following error when trying t...
# general
a
Hi, I am getting the following error when trying to build using a docker environment. Any suggestions?
Copy code
ProcessExecutionFailure: Process 'Building 2 requirements for src.python.example/main.pex from the python-default.lock resolve: fastapi<0.105.0,>=0.104.1, uvicorn<0.25.0,>=0.24.0.post1' failed with exit code 1.
stdout:

stderr:
There was 1 error downloading required artifacts:
1. pydantic-core 2.10.1 from <https://files.pythonhosted.org/packages/af/31/8e466c6ed47cddf23013d2f2ccf3fdb5b908ffa1d5c444150c41690d6eca/pydantic_core-2.10.1.tar.gz>
Docker env:
Copy code
docker_environment(
  name="python_bullseye",
  platform="linux_x86_64",
  image="python:3.11.6-bullseye@sha256:667f7084aaff6907534f1784ae6b58ccc409bb4bd8a24d9e02dee27584b9b2f7",
)
b
Is there any more context to the error? Can the install run manually in a docker container like that? E.g.
docker run python:3.11.6-bullseye@sha256:667f7084aaff6907534f1784ae6b58ccc409bb4bd8a24d9e02dee27584b9b2f7 pip install pydantic-core==2.10.1
or something like that.
a
Yes the install ran manually. That is all I get for the error message. The pex binary is defined as below
Copy code
pex_binary(
    name="main",
    entry_point="__init__.py",
    environment="python_bullseye",
    platforms=[
        "linux-x86_64-cp-311-cp311m"
    ]
)
If I package it using my local environment, it works. So there is something going on there that I don't quite understand yet.
b
Hm, strange. Does it work without the
platforms
? (In theory, without that, it’ll just package to match the ambient platform, ie the Python and glibc versions/architectures in the docker image)
a
Ok, that worked.
Thanks again for the help 🙏
Now when I run the docker image I get
Copy code
Failed to find compatible interpreter on path /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

Examined the following interpreters:
1.) /usr/bin/python3.11 CPython==3.11.2

No interpreter compatible with the requested constraints was found:

  Failed to resolve requirements from PEX environment @ /root/.pex/unzipped_pexes/597e926d0c16c0ebf20e514f0960a7d731c3bd66.
  Needed cp311-cp311-manylinux_2_36_aarch64 compatible dependencies for:
   1: pydantic-core==2.10.1
      Required by:
        pydantic 2.4.2
      But this pex had no ProjectName(raw='pydantic-core', normalized='pydantic-core') distributions.
b
Ah, that looks to mention aarch64 (aka ARM) cpu while your platform earlier had x86-64 (aka intel). Are you building on an arm cpu but deploying to intel? If so, you’ll need to resolve that… I don’t know off the top of my head if the docket environment allows specifying the platform.
a
Yeah I am on an ARM machine, and building for x86. I got there in the end by setting
--platform=amd64
in my Dockerfile
Copy code
pex_binary(
    name="main", 
    entry_point="__init__.py", 
    shebang="#!/usr/bin/python",
    platforms = [
        "manylinux2014_x86_64-cp-311-cp311",
    ],
)

docker_image(
    name="example_image",
)
Dockerfile
Copy code
FROM --platform=amd64 <http://gcr.io/distroless/python3-debian12|gcr.io/distroless/python3-debian12>
COPY src.python.example/main.pex /bin/main.pex
ENTRYPOINT ["python", "/bin/main.pex"]
b
Nice!
Two minor comments for iteration (if you want 🙂 ): • I'd suggest using
complete_platforms
rather than
platforms
: the
platforms
is an approximation that can lead to unexpected choices of dependencies and thus errors. See https://github.com/pantsbuild/pants/discussions/18756 (particularly "Again, we use
complete_platforms
to be able to build PEX files natively on macOS") for how this can work • It's possible to better utilise the docker layer caching by splitting third-party requirements and first-party sources into their own PEXes and layers. See those recipes and https://blog.pantsbuild.org/optimizing-python-docker-deploys-using-pants/
🚀 1