Skip to content

platform_machine markers evaluate against host kernel, not target interpreter, on cross-arch setups #18127

Open

Description

@alexreinking

Summary

When using uv on an aarch64 host to target an armv7 Python, platform_machine markers always evaluate to aarch64 (from uname -m) rather than reflecting the target interpreter's architecture. This means marker-conditional dependencies for armv7 are never selected.

Reproduction

Save the following script and run on an aarch64 Linux host:

#!/usr/bin/env bash
set -euo pipefail

# Reproducer for uv cross-architecture marker evaluation bug.
# Run on an aarch64 Linux host.

echo "=== Environment ==="
uname -m
uv --version

echo ""
echo "=== Install armv7 Python ==="
uv python install 3.11-armv7-gnueabihf

echo ""
echo "=== Set up test project ==="
WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT

cd "$WORKDIR"
uv init marker-test
cd marker-test

cat > pyproject.toml << 'PYPROJECT'
[project]
name = "marker-test"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "onnx==1.17.0; platform_machine == 'armv7l' or platform_machine == 'armv8l'",
    "onnx==1.18.0; platform_machine != 'armv7l' and platform_machine != 'armv8l'",
]

[tool.uv.sources]
onnx = { index = "piwheels", marker = "platform_machine == 'armv7l' or platform_machine == 'armv8l'" }

[[tool.uv.index]]
name = "piwheels"
url = "https://www.piwheels.org/simple"
explicit = true
PYPROJECT

echo ""
echo "=== Bug 1: platform_machine markers use uname -m, not target interpreter ==="
echo "The venv uses an armv7 interpreter, but platform_machine evaluates to aarch64."
export UV_PYTHON=3.11-linux-armv7-gnu
rm -rf .venv uv.lock
uv venv
echo "Interpreter: $(file "$(realpath .venv/bin/python3)")"
echo "uname -m: $(uname -m)"
echo "python platform.machine(): $(.venv/bin/python3 -c 'import platform; print(platform.machine())')"
timeout 15 uv sync --no-install-project 2>&1 | grep -i onnx || true
echo ""
echo "Expected: onnx==1.17.0 (armv7 interpreter)"
echo "Actual:   onnx==1.18.0 (marker matched aarch64 from uname -m)"

echo ""
echo "=== Bug 2: naming inconsistency ==="
echo "uv classifies the installed armv7 interpreter as armv7-gnu, but cannot install by that name:"
uv python install 3.11-linux-armv7-gnu 2>&1 || true

Here's the result of running it on my Raspberry Pi:

halidenightly@arm64-linux-3:~/tmp$ ./uv-bug-repro.sh 
=== Environment ===
aarch64
uv 0.10.4

=== Install armv7 Python ===
any-3.11-any-armv7-gnueabihf is already installed

=== Set up test project ===
Initialized project `marker-test` at `/tmp/tmp.zQVcaJOtiS/marker-test`

=== Bug 1: platform_machine markers use uname -m, not target interpreter ===
The venv uses an armv7 interpreter, but platform_machine evaluates to aarch64.
Using CPython 3.11.14 interpreter at: /home/halidenightly/.local/bin/python3.11
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
Interpreter: /home/halidenightly/.local/share/uv/python/cpython-3.11.14-linux-armv7-gnueabihf/bin/python3.11: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=fdd8b587b24d23536885c259c87c7861c68c3f42, not stripped
uname -m: aarch64
python platform.machine(): aarch64
   Building onnx==1.18.0

Expected: onnx==1.17.0 (armv7 interpreter)
Actual:   onnx==1.18.0 (marker matched aarch64 from uname -m)

=== Bug 2: naming inconsistency ===
uv classifies the installed armv7 interpreter as armv7-gnu, but cannot install by that name:
error: No download found for request: cpython-3.11-linux-armv7-gnu

Expected behavior

uv sync should resolve onnx==1.17.0 because the target Python is an armv7 binary.

Actual behavior

uv sync resolves onnx==1.18.0 because it evaluates platform_machine from uname -m (aarch64), which reflects the host kernel, not the target interpreter.

Note: platform.machine() returns the kernel architecture even from a 32-bit binary (it calls uname), so the issue is that uv should infer the target platform from the interpreter's ABI tags or sysconfig data rather than querying platform.machine().

Secondary issue: naming inconsistency

uv python install 3.11-armv7-gnueabihf installs successfully, but uv classifies the same binary on PATH as armv7-gnu. Requesting by the classified name fails:

$ uv python install 3.11-linux-armv7-gnu
error: No download found for request: cpython-3.11-linux-armv7-gnu

Environment

  • uv 0.10.4
  • Host: Ubuntu 22.04, aarch64 kernel
  • Target: cpython-3.11.14-linux-armv7-gnueabihf (uv-managed)

Activity

  1. added
    great writeup
    on Feb 22, 2026
  2. konstin commented on Feb 22, 2026

    @konstin
    Member

    Thank you for the annotated reproducer!

    What stands out to me is this part:

    echo "Interpreter: $(file "$(realpath .venv/bin/python3)")"
    echo "uname -m: $(uname -m)"
    echo "python platform.machine(): $(.venv/bin/python3 -c 'import platform; print(platform.machine())')"
    
    Interpreter: /home/halidenightly/.local/share/uv/python/cpython-3.11.14-linux-armv7-gnueabihf/bin/python3.11: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, > BuildID[sha1]=fdd8b587b24d23536885c259c87c7861c68c3f42, not stripped
    uname -m: aarch64
    python platform.machine(): aarch64
    

    Note: platform.machine() returns the kernel architecture even from a 32-bit binary (it calls uname), so the issue is that uv should infer the target platform from the interpreter's ABI tags or sysconfig data rather than querying platform.machine().

    I'm not sure we can this that easily. PEP 508 define platform_machine as the value platform.machine(), so the rest of the Python stack expects them to be the same. The platform.machine() docs don't say anything about how this is implemented, this is arguably either a bug in CPython or in the emulation layer.

    More practically, I think the problem is that you're not doing a cross install (--python-platform), instead, UV_PYTHON looks like a native Python interpreter to uv, so uv uses the "real" values from querying that Python interpreter, instead hardcoded values for the target platform. There's currently only 64-bit support for arm in --python-platform, though it's possible to add more platforms to it.

  3. alexreinking commented on Feb 22, 2026

    @alexreinking
    Author

    Thank you for the annotated reproducer!

    You're welcome! I try to write the bug reports I hope to receive myself 🙂

    There's currently only 64-bit support for arm in --python-platform, though it's possible to add more platforms to it.

    Yeah, this is why I went down this road at all. Actually, a few times I swear I made it work but I can't reliably reproduce the circumstances under which it did. Maybe there's some race to populate the uv interpreter cache or something? I couldn't figure it out.

    Anyway, it would be really great to get some broader support in --python-platform. In my real, non-reproducer, case, I'm trying to get Halide working on an armv8l Raspberry Pi (though armv7l wheels work just fine).

    I'm not afraid to get my hands dirty here and contribute, but I can't say I know Rust, let alone uv's codebase, very well. Maybe to start, I could gather more information for you? What would be helpful?

  4. alexreinking commented on Feb 23, 2026

    @alexreinking
    Author

    Here's some more vexing behavior. Normally one should be able to override the behavior of uname -m with the setarch command. I'll start by creating a new virtual environment with 3.11-armv7-gnueabihf:

    alex@arm64-linux-4:~$ uv python install 3.11-armv7-gnueabihf
    Installed Python 3.11.14 in 6.83s
     + cpython-3.11.14-linux-armv7-gnueabihf
    alex@arm64-linux-4:~$ uv venv --python 3.11-armv7-gnueabihf test-venv
    Using CPython 3.11.14
    Creating virtual environment at: test-venv
    Activate with: source test-venv/bin/activate
    alex@arm64-linux-4:~$ source test-venv/bin/activate
    (test-venv) alex@arm64-linux-4:~$ 

    Now I'll go ahead and check to make sure that my Python is the architecture I expect:

    (test-venv) alex@arm64-linux-4:~$ file -L $(which python)
    /home/alex/test-venv/bin/python: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=fdd8b587b24d23536885c259c87c7861c68c3f42, not stripped
    (test-venv) alex@arm64-linux-4:~$ python --version
    Python 3.11.14

    Looks good. Now let's print the architecture as I did above:

    (test-venv) alex@arm64-linux-4:~$ python3 -c 'import platform; print(platform.machine())'
    aarch64

    Frustrating, but we have setarch to help out:

    (test-venv) alex@arm64-linux-4:~$ setarch armv7l python3 -c 'import platform; print(platform.machine())'
    armv8l

    Hmm. Some progress, but this isn't quite the arch I asked for. Hopefully tooling is smart enough to know armv8l is backwards compatible with armv7l. Just in case, I'll set up a quick requirements.txt file that should be tolerant to both markers:

    (test-venv) alex@arm64-linux-4:~$ cat >requirements.txt <<-EOF
    onnx==1.17.0; platform_machine == 'armv7l' or platform_machine == 'armv8l'
    onnx==1.18.0; platform_machine != 'armv7l' and platform_machine != 'armv8l'
    EOF

    Now let's ask uv to install these requirements:

    (test-venv) alex@arm64-linux-4:~$ uv pip install --dry-run -r requirements.txt 
    Using Python 3.11.14 environment at: test-venv
    Resolved 4 packages in 890ms
    Would download 4 packages
    Would install 4 packages
     + numpy==2.4.2
     + onnx==1.18.0
     + protobuf==6.33.5
     + typing-extensions==4.15.0

    That's not the most surprising thing since we know now that Python still sees aarch64 as its platform_machine. So let's see what happens when we run under setarch:

    (test-venv) alex@arm64-linux-4:~$ setarch armv7l uv pip install --dry-run -r requirements.txt 
    Using Python 3.11.14 environment at: test-venv
    Resolved 4 packages in 51ms
    Would download 4 packages
    Would install 4 packages
     + numpy==2.4.2
     + onnx==1.18.0
     + protobuf==6.33.5
     + typing-extensions==4.15.0

    It's somehow ignoring the setarch environment. Let me grep verbose output for platform_machine or aarch

    (test-venv) alex@arm64-linux-4:~$ setarch armv7l uv pip install --dry-run -r requirements.txt -vv 2>&1 | grep -E 'platform_machine|aarch'
    DEBUG At least one requirement is not satisfied: onnx==1.18.0 ; platform_machine != 'armv7l' and platform_machine != 'armv8l'
    DEBUG Adding direct dependency: onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}>=1.18.0, <1.18.0+
    TRACE Chose package for decision: onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}. remaining choices: onnx
    DEBUG Searching for a compatible version of onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'} (>=1.18.0, <1.18.0+)
    DEBUG Adding transitive dependency for onnx==1.18.0: onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}==1.18.0
    TRACE Chose package for decision: onnx. remaining choices: onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}
    TRACE Chose package for decision: onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}. remaining choices: typing-extensions, numpy, protobuf
    DEBUG Searching for a compatible version of onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'} (==1.18.0)
    TRACE Assigned packages: root==0a0.dev0, onnx==1.18.0, onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}==1.18.0
    TRACE Assigned packages: root==0a0.dev0, onnx==1.18.0, onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}==1.18.0, numpy==2.4.2
    TRACE Assigned packages: root==0a0.dev0, onnx==1.18.0, onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}==1.18.0, numpy==2.4.2, protobuf==6.33.5
    TRACE Assigned packages: root==0a0.dev0, onnx==1.18.0, onnx{platform_machine != 'armv7l' and platform_machine != 'armv8l'}==1.18.0, numpy==2.4.2, protobuf==6.33.5, typing-extensions==4.15.0
    TRACE Resolution: ResolverEnvironment { kind: Specific { marker_env: ResolverMarkerEnvironment(MarkerEnvironment { inner: MarkerEnvironmentInner { implementation_name: "cpython", implementation_version: StringVersion { string: "3.11.14", version: "3.11.14" }, os_name: "posix", platform_machine: "aarch64", platform_python_implementation: "CPython", platform_release: "5.10.110-rockchip-rk3588", platform_system: "Linux", platform_version: "#1.0.6 SMP Thu Jun 1 00:04:22 CST 2023", python_full_version: StringVersion { string: "3.11.14", version: "3.11.14" }, python_version: StringVersion { string: "3.11", version: "3.11" }, sys_platform: "linux" } }) } }
    TRACE Resolution edge:     0a0.dev0 -> 1.18.0 ; platform_machine != 'armv7l' and platform_machine != 'armv8l'

    So the ResolverEnvironment still has aarch64 somehow. Will get to the bottom of how/why.

  5. alexreinking commented on Feb 23, 2026

    @alexreinking
    Author

    Okay, I think there is also a cache invalidation bug! I don't know how uv caches interpreter info, but if I now run this, look, it says it would install onnx==1.17.0:

    (test-venv) alex@arm64-linux-4:~$ uv cache clean 
    Clearing cache at: .cache/uv
    Removed 12 files (3.8MiB)
    (test-venv) alex@arm64-linux-4:~$ setarch armv7l uv pip install --dry-run -r requirements.txt
    Using Python 3.11.14 environment at: test-venv
    Resolved 3 packages in 976ms
    Would download 3 packages
    Would install 3 packages
     + numpy==2.4.2
     + onnx==1.17.0
     + protobuf==6.33.5

    I opened #18163 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    great writeup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions