hey all. having some struggles with macos + pex + ...
# general
g
hey all. having some struggles with macos + pex + docker. error when doing `pants run src/py/blah:docker`:
Copy code
❯ pants run src/py/blah:docker
17:27:32.55 [INFO] Completed: Building docker image app:latest
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.10 CPython==3.10.13

No interpreter compatible with the requested constraints was found:

  A distribution for cryptography could not be resolved for /usr/local/bin/python3.10.
  Found 1 distribution for cryptography that do not apply:
  1.) The wheel tags for cryptography 41.0.3 are cp37-abi3-macosx_10_12_universal2 which do not match the supported tags of /usr/local/bin/python3.10:
  cp310-cp310-manylinux_2_36_aarch64
  ... 517 more ...
i've tried a few
--platform
iterations to no avail. also started to look at the experimental environments(
docker_environment
in particular). but i'm really struggling to get a PEX to run in a container.
b
Heya, could you show the
BUILD
file? Especially the
pex_binary
target? Also, https://github.com/pantsbuild/pants/discussions/18756 might be very relevant to you. It describes what we do for cross-building linux docker images from a macOS host
g
BUILD.py
ah, that discussion looks quite relevant. going to give it a read, thanks.
b
Yeah, the key will be using
platforms
or
complete_platforms
in some form, or else the PEX binary will be only compatible with the host that pants is running on (i.e. macOS), not necessarily the docker image. From a quick glance, the
platforms
args may not be working because they use the
m
suffix which apparently doesn't apply in 3.8 and newer. I don't know what the exact correct form is, as we use
complete_platforms
JSON files appropriate for the specific docker image we're building for (that discussion has how to compute them)
e
As @broad-processor-92400 nudges - please just use a complete platform, (abbreviated) platform is an old hack from the Twitter days (when you don't understand a thing, never just mash your keyboard was not followed in those days!). That said, you find out like so:
Copy code
$ python3.10 -mvenv example.venv
$ example.venv/bin/pip install pex
$ example.venv/bin/pex --help | grep -A25 "\--platform "
  --platform PLATFORMS, --abbreviated-platform PLATFORMS
                        The (abbreviated) platform to build the PEX for. This
                        option can be passed multiple times to create a multi-
                        platform pex. To use the platform corresponding to the
                        current interpreter you can pass `current`. To target
                        any other platform you pass a string composed of
                        fields: <platform>-<python impl abbr>-<python
                        version>-<abi>. These fields stem from wheel name
                        conventions as outlined in
                        <https://www.python.org/dev/peps/pep-0427#file-name->
                        convention and influenced by
                        <https://www.python.org/dev/peps/pep-0425>. For the
                        current interpreter at
                        /home/jsirois/dev/pantsbuild/jsirois-
                        pex/example.venv/bin/python3.10 the full platform
                        string is manylinux_2_35_x86_64-cp-3.10.12-cp310. To
                        find out more, try `PEX_TOOLS=1 example.venv/bin/pex
                        interpreter --all --verbose --indent 4` to print out
                        the platform for all interpreters on the $PATH or
                        `PEX_TOOLS=1 /home/jsirois/dev/pantsbuild/jsirois-
                        pex/example.venv/bin/python3.10 example.venv/bin/pex
                        interpreter --verbose --indent 4` to inspect the
                        single interpreter
                        /home/jsirois/dev/pantsbuild/jsirois-
                        pex/example.venv/bin/python3.10. (default: [])
  --complete-platform COMPLETE_PLATFORMS
Note the example in the help string:
Copy code
For the current interpreter at /home/jsirois/dev/pantsbuild/jsirois-pex/example.venv/bin/python3.10 the full platform string is manylinux_2_35_x86_64-cp-3.10.12-cp310.
So that's
manylinux_2_35_x86_64-cp-3.10.12-cp310
. Pants supplies the
--manylinux
flag separately though; so you want just
linux_x86_64-cp-3.10.12-cp310
. Note this includes the patch version (
12
), you can also try
linux_x86_64-cp-310-cp310
(no patch version), but this is even less precise and will outright fail for any dependency that specifies an environment marker of
python_full_version
- which requires the patch.
g
awesome. getting on to an instance that is x86 and running the
pex3 interpreter
commands to get the json and building a pex with that seems to work. next step trying to get the docker container to be happy.
thanks for the help @enough-analyst-54434 and @broad-processor-92400.