Hi guys, I'm on apple M3, having issues with runni...
# general
b
Hi guys, I'm on apple M3, having issues with running docker images built by pants package. A colleague of mine using arch linux was able to run the docker image without problem.
Copy code
docker run -it --rm -p 8000:8000 sha256:ae5bd62b0c5dacbc2c711a8af9aaa6eae99eed00a20f1f392a1cbcb53084a7ea
The error I'm getting:
Copy code
Failed to find compatible interpreter on path /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

Examined the following interpreters:
1.) /usr/local/bin/python3.12 CPython==3.12.6
2.)       /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/d68b21b11fd496463c05648307e5236930357f95.
  Needed cp312-cp312-manylinux_2_36_aarch64 compatible dependencies for:
   1: pydantic-core==2.23.4
      Required by:
        pydantic 2.9.2
      But this pex had no ProjectName(raw='pydantic-core', validated=False, normalized='pydantic-core') distributions.
   2: protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.20.2
      Required by:
        googleapis-common-protos 1.65.0
      But this pex had no ProjectName(raw='protobuf', validated=False, normalized='protobuf') distributions.
   3: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5
      Required by:
        google-api-core 2.20.0
      But this pex had no ProjectName(raw='protobuf', validated=False, normalized='protobuf') distributions.
   4: protobuf<6.0.0dev,>=3.19.0
      Required by:
        proto-plus 1.24.0
      But this pex had no ProjectName(raw='protobuf', validated=False, normalized='protobuf') distributions.
   5: charset-normalizer<4,>=2
      Required by:
        requests 2.32.3
      But this pex had no ProjectName(raw='charset-normalizer', validated=False, normalized='charset-normalizer') distributions.
   6: grpcio<2.0dev,>=1.33.2; extra == "grpc"
      Required by:
        google-api-core 2.20.0
      But this pex had no ProjectName(raw='grpcio', validated=False, normalized='grpcio') distributions.
   7: protobuf<6.0dev,>=5.26.1
      Required by:
        grpcio-status 1.66.1
      But this pex had no ProjectName(raw='protobuf', validated=False, normalized='protobuf') distributions.
   8: grpcio>=1.66.1
      Required by:
        grpcio-status 1.66.1
      But this pex had no ProjectName(raw='grpcio', validated=False, normalized='grpcio') distributions.
   9: grpcio<2.0dev,>=1.49.1; python_version >= "3.11" and extra == "grpc"
      Required by:
        google-api-core 2.20.0
      But this pex had no ProjectName(raw='grpcio', validated=False, normalized='grpcio') distributions.
   10: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.2
      Required by:
        google-cloud-aiplatform 1.67.1
        google-cloud-resource-manager 1.12.5
      But this pex had no ProjectName(raw='protobuf', validated=False, normalized='protobuf') distributions.
   11: google-crc32c<2.0dev,>=1.0
      Required by:
        google-resumable-media 2.7.2
        google-cloud-storage 2.18.2
      But this pex had no ProjectName(raw='google-crc32c', validated=False, normalized='google-crc32c') distributions.
   12: grpcio<2.0.0dev,>=1.44.0
      Required by:
        grpc-google-iam-v1 0.13.1
      But this pex had no ProjectName(raw='grpcio', validated=False, normalized='grpcio') distributions.
   13: grpcio<2.0.0.dev0,>=1.44.0; extra == "grpc"
      Required by:
        googleapis-common-protos 1.65.0
      But this pex had no ProjectName(raw='grpcio', validated=False, normalized='grpcio') distributions.
   14: protobuf!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.2
      Required by:
        grpc-google-iam-v1 0.13.1
      But this pex had no ProjectName(raw='protobuf', validated=False, normalized='protobuf') distributions.
   15: shapely<3.0.0dev
      Required by:
        google-cloud-aiplatform 1.67.1
      But this pex had no ProjectName(raw='shapely', validated=False, normalized='shapely') distributions.
   16: jiter<1,>=0.4.0
      Required by:
        openai 1.47.1
      But this pex had no ProjectName(raw='jiter', validated=False, normalized='jiter') distributions.
Things I've tried: • added
platforms=["linux-x86_64-cp-37-cp37m", "macosx_10_15_x86_64-cp-38-cp38"]
suggested here: https://www.pantsbuild.org/stable/docs/python/goals/package#injecting-command-line-arguments-and-environment-variables, to pex_binary, but it gives syntax error. • Re-installed pants with brew, made sure the pantsd is running in arm64 mode. • using zsh instead of bash, making sure it's running in arm64 •
pants package :: --no-watch-filesystem --no-pantsd
This is my dockerfile:
Copy code
FROM europe-docker.pkg.dev/ewx-global/docker-hub-proxy/python:3.12

WORKDIR /app

COPY context.ewx-opsy.src.ewx_opsy/bin.pex /app/bin.pex

CMD ["/app/bin.pex"]
This is my BUILD file inside src/ewx_opsy
Copy code
python_sources(
    resolve="opsy",
    dependencies=[
        ":settings_files",
    ],
)

resources(
    name="settings_files",
    sources=["*.toml"],
)

pex_binary(
    name="bin",
    script="uvicorn",
    args=["ewx_opsy.server:app", "--host=0.0.0.0", "--port=8000", "--log-level=debug"],
    # execution_mode="venv",
    dependencies=[
        "./server.py",
        "context/ewx-opsy:poetry#uvicorn",
    ],
    resolve="opsy",
    resolve_local_platforms=True
)
b
Heya, sorry for the trouble. That pex is looks like it is being built natively for macOS, but then being run on Linux. You're on the right track with
platforms=...
but that's been deprecated and removed because it wasn't reliable. The better way is to use
complete_platforms=...
: https://www.pantsbuild.org/prerelease/docs/python/overview/pex#setting-the-target-platforms-for-a-pex (linking to prerelease docs because they're better than the current stable)
Looks like the docs you found weren't updated after we deprecated and removed
platforms
, so you were always going to have trouble to get this working! that's not very helpful of us (the pants project) 🙂 Are you in a position to file an issue about that problem in the docs? Maybe even open a pull request to fix them? Let me know if I can help 🙂
b
Hi, we've tried the above solution with the same error as before.
Copy code
python_sources(
    resolve="opsy",
    dependencies=[
        ":settings_files",
    ],
)

resources(
    name="settings_files",
    sources=["*.toml"],
)

file(
    name="linux",
    source="linux.json",
)

pex_binary(
    name="bin",
    script="uvicorn",
    args=["ewx_opsy.server:app", "--host=0.0.0.0", "--port=8000", "--log-level=debug"],
    # execution_mode="venv",
    dependencies=[
        "./server.py",
        "context/ewx-opsy:poetry#uvicorn",
    ],
    resolve="opsy",
    complete_platforms=[":linux"],
)
the linux.json looks like this, which compatible_tags has more than 1000 items
Copy code
{
  "path": "/usr/bin/python3.12",
  "compatible_tags":[
    "cp312-cp312-manylinux_2_40_x86_64",
    "cp312-cp312-manylinux_2_39_x86_64",
.....
]
  "marker_environment": {
    "implementation_name": "cpython",
    "implementation_version": "3.12.6",
    "os_name": "posix",
    "platform_machine": "x86_64",
    "platform_python_implementation": "CPython",
    "platform_release": "6.10.10-arch1-1",
    "platform_system": "Linux",
    "platform_version": "#1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000",
    "python_full_version": "3.12.6",
    "python_version": "3.12",
    "sys_platform": "linux"
  }
}
b
What does “no success” mean? Same error as before? Guessing: there’s likely still a CPU architecture difference. That causing the pex to be built for x86-64, but the docker run appears to be aarch64 (aka arm64). That is, the image is arm but the pex is intel. You can either fix this by: 1. having a second complete platform for arm too 2. Ensuring the image is built for intel I’m on phone now, so can’t provide specific guidance. https://github.com/pantsbuild/pants/discussions/18756 is somewhat-outdated details of what we do for option 1.
p
We sorted this out by making all containers linux/x64 and building everything inside docker to get builds working https://www.pantsbuild.org/blog/2024/07/01/building-linux-on-osx-silicon
1
but the original problem (container built on x86 won't run on m3) sounds like a misconfig of the m3 machine that is not running it under rosetta
b
@broad-processor-92400 yes same error as before.
@powerful-scooter-95162 thanks will give it a try