Hey everyone - I'm dealing with what I'd imagine i...
# general
g
Hey everyone - I'm dealing with what I'd imagine is a pretty common problem here on Mac. I'm running pants on my macbook with apple silicon and things have been running super smoothly. However, when wanting to build a docker image I'm running into the following error:
Copy code
Step 3/10 : RUN PEX_TOOLS=1 /usr/local/bin/python3.11 /binary.pex venv --scope=deps --compile /bin/app                                                      
 ---> Running in e9df5526d509                                                                                                                               
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.11 CPython==3.11.6

No interpreter compatible with the requested constraints was found:
                                                                                                                                                            
  A distribution for aiohttp could not be resolved for /usr/local/bin/python3.11.                                                                           
  Found 1 distribution for aiohttp that do not apply:
  1.) The wheel tags for aiohttp 3.9.0b0 are cp311-cp311-macosx_10_9_x86_64 which do not match the supported tags of /usr/local/bin/python3.11:             
  cp311-cp311-manylinux_2_36_aarch64                                                                                                                        
  ... 562 more ...
What would be the best way to get around this issue?
e
It is pretty common that people expect a PEX (~binary) built on a Mac somehow magically works on Linux. There is no magic provided by Pants though. There are a few ways to get this working using Pants though and this has been discussed at least dozens of times on slack. Have you given Slack search a try? If not, perhaps try that 1st.
g
Can you suggest an avenue? I've searched the slack but clearly not found anything I can map to my issue here. Is this somethign I need to solve when building the pex? or something to solve when building in docker?
h
Search slack for "complete_platforms", that should give you some leads
A pex is like a binary, you have to build it for the platform you plan to run it on. If this platform is Docker, that means linux (and more specifically, a combination of linux glibc version+python interpreter specification).
You can look into building the pex in a docker container (either by running Pants inside docker, or using the Pants "environments" feature), or, you can build a cross-platform pex using
complete_platforms
, but this requires that all transitive third-party dependencies are available in binary wheel form, and this may not be the case for your deps, unless you build them yourself and put them in a pypi-like artifact repository for Pants to resolve from.
c
you build them yourself and put them in a pypi-like artifact repository for Pants to resolve from.
FWIW We have a lot of mac users and more or less follow the guide in https://github.com/pantsbuild/pants/discussions/18756 with
complete_platforms
Concretely in
pants.toml
we set
Copy code
[python.resolves_to_only_binary]
default = [":all:"]
And have some pipeline with https://cibuildwheel.readthedocs.io/en/stable/ configured to build wheels for PyPI packages. This makes things smooth for mac user (and really with glibc versions Linux users eventually need this to) albeit at the cost of shifting some of the burden to a centralized "deal with annoying 3rdparty stuff" team.
g
Hey thanks for giving me some avenues to pursue - much more helpful than the initial comment. Appreciate it guys
e
Thanks for grading my attempt.
😘 1
I've worked on this project for 13 years and its people like you that make OSS support not worth it.
g
What shall I do? Uninstall pants from my computer? Is this not the place to ask for help? If you don't want to help me then don't.
Just to circle back here: using the environments feature has worked perfectly for me, once again thank you for the response Benjy: [environments-preview.names] linux = "//:linux" local = "//:local"
and then the root BUILD:
Copy code
python_requirements(name="requirements")

docker_environment(
  name="linux",
  image="python:3.11-slim",
  fallback_environment="local"
)

local_environment(name="local")

__defaults__(all=dict(environment="linux"))