Hey everyone! new to pants here. I'm trying to bui...
# general
f
Hey everyone! new to pants here. I'm trying to build a simple api, but I keep running into this error with different dependencies
Copy code
ProcessExecutionFailure: Process 'Building 1 requirement for service/bin.pex from the python-default.lock resolve: uvicorn[standard]==0.20.0' failed with exit code 1.
stdout:

stderr:
No pre-built wheel was available for httptools 0.6.0.
Successfully built the wheel httptools-0.6.0-cp39-cp39-macosx_11_0_arm64.whl from the sdist httptools-0.6.0.tar.gz but it is not compatible with the requested foreign target abbreviated platform cp310-cp310m-linux_x86_64.
You'll need to build a wheel from httptools-0.6.0.tar.gz on the foreign target platform and make it available to Pex via a `--find-links` repo or a custom `--index`.
for reference, here is my
pants.toml
Copy code
[GLOBAL]
pants_version = "2.16.0"
backend_packages = [
    "pants.backend.docker",
    "pants.backend.python",
    "pants.backend.python.lint.black",
    "pants.backend.python.lint.flake8",
]

[docker]
env_vars = [
    "DOCKER_BUILDKIT=0",
]

[python]
interpreter_constraints = ["==3.10.*"]
enable_resolves = true
resolves = { python-default = "python-default.lock" }

[python-bootstrap]
search_path = ["<PYENV>"]

[source]
root_patterns = [
    "/",
]

[anonymous-telemetry]
enabled = false
and here is the build file in question
Copy code
python_sources(
    name="service",
)

pex_binary(
    name="bin",
    platforms=[
        "macosx-arm64-cp-310-m",
        "linux-x86_64-cp-310-m",
    ],
)

docker_image(
    name="test-service",
)
It seems like the pex build agent is using 3.9 for some reason ...
f
It looks like the wheel built for
httptools
is for macOS but is being used for Linux.
f
I get the same error if I remove the
linux-x86*
platform above
it's fetching the 3.9 wheels for some reason rather than 3.10
e
is the universal2 wheel supposed to be for mac arm?
f
okay ... removed most of the dependencies and got it build. looked into the PEX
__main__.py
Copy code
#!/usr/bin/env python3.9
e
The python 3.9 thing is a red herring here I believe. @fast-refrigerator-12613 if the httptools 0.6.0 universal2 wheel for mac arm? I'm mac ignorant for the most part.
f
to John's point, https://pypi.org/project/httptools/#files looks like it only has those "universal2" wheels available
(besides the linux ones)
e
@fast-refrigerator-12613 if universal2 means arm, then please try this: https://www.pantsbuild.org/docs/reference-python#pip_version and set it to the highest version.
Looks like the answer is yes:
Copy code
$ file httptools-0.6.0/httptools/parser/parser.cpython-311-darwin.so
httptools-0.6.0/httptools/parser/parser.cpython-311-darwin.so: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit x86_64 bundle, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL>] [arm64:Mach-O 64-bit arm64 bundle, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL>]
So, @fast-refrigerator-12613 please try:
Copy code
[python]
pip_version = "23.0.1"
f
👍 trying now
e
The default Pip is 20.3.4 which means 20 -> 2020 which ~predates mac arm and universal2.
f
it built!!
but ...
Copy code
dist/services.test_service/bin.pex        
pyenv: python3.9: command not found

The `python3.9' command exists in these Python versions:
  3.9.16

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.
e
You can set a custom shebang as you wish,
f
sorry - i'm new
that shebang is being set by pex though
f
ahhh
so much to configure ... so much power
oh, I can also run it directly with my interpreter of choice. cool
e
Yes
f
alright! thanks for the help!!!
In this end, I needed to add this to
pants.toml
Copy code
[pex]
executable_search_paths=["<PYENV>"]
edit: nvm. didn't work.
still stuck on this one. The previous solutions were false builds. The PEX didn't actually run.
¯\_(ツ)_/¯
e
What do you mean didn't run?
f
It didn't add any code to the pex binary
it was empty
e
Ok, obviously not enough info to help out. You did say https://pantsbuild.slack.com/archives/C046T6T9U/p1690231247306839?thread_ts=1690230576.272629&amp;cid=C046T6T9U - but just provide details if you need more assistance.
f
Will do. Stepped away to make dinner. I’ll try to narrow it down further and post again. I’m adding pants to an existing project, so I suspect it’s a bigger dependency issue that other tools weren’t catching
Okay. I wasn't specifying the platforms correctly:
Copy code
pex_binary(
    name="bin",
    entry_point="foo.main",
    shebang="#!/usr/bin/env python3",
    platforms=[
        "macosx_11_0_arm64-cp-310-cp310",
        "linux_aarch64-cp-310-cp310",
    ],
)
This finally fixed everything. Thanks for the help John and tdyas!
e
You're welcome. You probably want to think about switching to complete platforms going forward - platforms is an old Twitter hack that will bite you at some point with a clear error about a missing environment marker, but it is an avoidable error nonetheless: https://www.pantsbuild.org/docs/reference-pex_binary#codecomplete_platformscode