https://pantsbuild.org/ logo
#general
Title
# general
f

famous-architect-76219

01/26/2023, 1:05 PM
Hello, I'm playing with Pants, I'm trying to build docker image that include a basic python script that depends on 3rd party library. I've choose
pydantic
library. I'm building locally PEX with the following snippet in the BUILD and it is running fine on my laptop:
Copy code
pex_binary(
    name="pydantic-cli",
    entry_point="main.py",
    dependencies=[
        "projects/py/project_2:poetry#pydantic",
    ]
)
Now I'm trying to pack this PEX into the Docker, so I've added the following snippet to the BUILD
Copy code
docker_image(
    name="pydantic-cli-docker",
    dependencies=[
        ":pydantic-cli",
    ]
)
I'm able to
pack
the docker image, but when I'm running the container it fails:
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.9 CPython==3.9.16

No interpreter compatible with the requested constraints was found:

  A distribution for pydantic could not be resolved for /usr/local/bin/python3.9.
  Found 2 distributions for pydantic that do not apply:
  1.) The wheel tags for pydantic 1.10.4 are cp39-cp39-macosx_10_9_x86_64 which do not match the supported tags of /usr/local/bin/python3.9:
  cp39-cp39-manylinux_2_28_aarch64
  ... 304 more ...
  2.) The wheel tags for pydantic 1.10.4 are cp39-cp39-macosx_11_0_arm64 which do not match the supported tags of /usr/local/bin/python3.9:
  cp39-cp39-manylinux_2_28_aarch64
  ... 304 more ...
Now
pydantic
is coming with pre-compiled binaries in the wheel, but for some reason it finds them incompatible. Note: My laptop is M1 Macbook I would like to be able to debug such scenarios alone, but I'm not sure where to start here, please advise.
e

enough-analyst-54434

01/26/2023, 1:14 PM
Sorry to be short, but to maybe help you along: if you build a thing on your Mac how do you expect it to work on Linux. It's true cross-building is a thing, but Pants does not do that.
And here is the tail end of a thread about the ~same thing with a concrete example of how to get a complete platform specification for a docker image: https://pantsbuild.slack.com/archives/C046T6T9U/p1674588059192949?thread_ts=1674529927.758439&cid=C046T6T9U
I guess the problem here is you may be expecting our docker integration to see a docker image depends on a pex_binary and so magically arrange all this for you. It does not. You have to be aware of the change of platform from your Mac to Linux and deal with that yourself currently. This is Python and pex_binary aside. If you had a go binary, same issue. You'd need to arrange to (cross) build a Linux go binary on your Mac to use in the Linux container.
There is new support for having Pants help out, but it's only in 2.15+ and I'm I'll informed about it. See: + https://www.pantsbuild.org/v2.15/docs/reference-docker_environment + https://www.pantsbuild.org/v2.15/docs/reference-pex_binary#codeenvironmentcode
f

famous-architect-76219

01/26/2023, 1:26 PM
Thanks a lot @enough-analyst-54434
@enough-analyst-54434 it seems that I'm missing some step. I've the JSON file, now I want to add to the
pex_binary
the
complete_platforms
- but what should be the value there? According to documentation it should be "The platforms the built PEX should be compatible with."
OK, I got it: First need to add the JSON file as
file
in BUILD:
Copy code
file(
    name="linux", 
    source="python3.9-complete-platform.json"
)
Next use it in the `complete_platforms`:
Copy code
pex_binary(
    name="pydantic-cli",
    entry_point="main.py",
    dependencies=[
        "projects/py/project_2:poetry#pydantic",
    ],
    complete_platforms=[
        ":linux"
    ]
)
c

curved-television-6568

01/26/2023, 2:41 PM
Hi @famous-architect-76219 ๐Ÿ‘‹ This is a common enough issue that Pants could potentially provide a little more context along with this error message to help out. Itโ€™s a balancing act though, as we donโ€™t want to give the wrong context for other errors as that would be counter productive even damaging. (ps. also you may want to edit your previous mentions to be that of @enough-analyst-54434 rather than
Josh Reed
๐Ÿ˜‰ )
๐Ÿ˜… 1
f

famous-architect-76219

01/26/2023, 4:59 PM
Thanks @curved-television-6568 ๐Ÿ™ƒ
๐Ÿ‘Œ 1
c

curved-television-6568

01/28/2023, 2:07 PM
7 Views