Skip to content

Autogen interpreter script uses #!/usr/bin/env python3 instead of meson's python, breaking builds where multiple python3s exist on PATH #41895

@DrScottN

Description

@DrScottN

Hello; I have wanted to build sage from source on NixOS for awhile now. I persuaded a Claude to get it working (it succeeded!), and it requested I open an issue regarding the following. I've checked the literal claims below, and I think it's correct, but I am not an expert. (I suspect this is a separate issue; but mesonbuild/meson#7372 is referenced in the relevant meson.build file, and it is now marked as 'Not planned'.)


In src/sage/ext/interpreters/meson.build, the custom command at line 27 invokes main.py directly:

command: ['../../../sage_setup/autogen/interpreters/__main__.py', '@OUTDIR@'],

This script has #!/usr/bin/env python3, so it runs whichever python3 the OS finds first on PATH. When building in environments like NixOS where multiple python3 interpreters exist (some without build dependencies like jinja2; these will almost always appear because nix will create other python's for other build dependencies, for eg, pkgs.meson), this fails with ModuleNotFoundError even though meson-python's own python has all required packages.

The fix would be to use meson's python interpreter explicitly:

command: [py, '../../../sage_setup/autogen/interpreters/__main__.py', '@OUTDIR@'],

where py is the python found by meson (already used elsewhere in the build and this particular custom_target call). This ensures the script runs with the same interpreter that has all build dependencies.

Workaround: Setting PYTHONPATH to the wrapped python's site-packages in the shell environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions