Skip to content

INCLUDEPY is incorrect #374

Closed
Closed

Description

@ngoldbaum

I'm experimenting with using a python-build-standalone python executable in CI on some projects like PyO3 and NumPy and am running into some issues.

The biggest one so far is that INCLUDEPY points to a non-existent path:

$  python -msysconfig | grep INCLUDEPY
	CONFINCLUDEPY = "/install/include/python3.13t"
	INCLUDEPY = "/install/include/python3.13t"

This makes it difficult to build C extensions against this version of Python, since it looks like libraries tend to check INCLUDEPY.

Interestingly, include is fine:

$ python -msysconfig | grep include
	include = "/Users/goldbaum/.local/share/uv/python/cpython-3.13.0+freethreaded-macos-aarch64-none/include/python3.13t"
	platinclude = "/Users/goldbaum/.local/share/uv/python/cpython-3.13.0+freethreaded-macos-aarch64-none/include/python3.13t"

I see that there is prior discussion about these /install paths being hard to update, although maybe since one path is updated we can update INCLUDEPY?

Activity

  1. ngoldbaum commented on Oct 18, 2024

    @ngoldbaum
    Author

    We could also update the libraries to get the include path from 'include', but it would be nice if libraries that introspect Python to try to ask questions like this didn't have to get updates to work with python-build-standalone builds.

  2. zanieb commented on Oct 18, 2024

    @zanieb
    Member

    Thanks for the report. I wonder how include gets derived? It's not like the build knows it'll be unpacked there. I worry this is an upstream CPython behavior?

  3. ngoldbaum commented on Oct 18, 2024

    @ngoldbaum
    Author

    I stepped through the standard library in a debugger. It looks like sys.get_path('include') ends up going into _expand_vars here, which then substitutes the correct path from the templates in the _INSTALL_SCHEMES dictionary.

    > /Users/goldbaum/.local/share/uv/python/cpython-3.13.0+freethreaded-macos-aarch64-none/lib/python3.13t/sysconfig/__init__.py(277)_expand_vars()
    -> value = os.path.expanduser(value)
    (Pdb) p _INSTALL_SCHEMES[scheme]['include']
    '{installed_base}/include/{implementation_lower}{py_version_short}{abiflags}'
    (Pdb) p _subst_vars('{installed_base}/include/{implementation_lower}{py_version_short}{abiflags}', vars)
    '/Users/goldbaum/.local/share/uv/python/cpython-3.13.0+freethreaded-macos-aarch64-none/include/python3.13t'
    

    INCLUDEPY on the other hand it looks like is directly written to the binary and comes from get_config_vars(). So it looks like this is the intended behavior and maybe the downstream libraries are doing the incorrect thing by checking INCLUDEPY?

    I can certainly make a PyO3 patch that checks sysconfig.get_path('include') if INCLUDEPY isn't a valid path. I already did that for NumPy in numpy/numpy#27581.

  4. zanieb commented on Oct 18, 2024

    @zanieb
    Member

    Thank you! That makes sense to me. The alternative is to change the INCLUDEPY value when the standalone distributions are installed — but I don't think we can do anything at build time.

  5. ngoldbaum commented on Oct 18, 2024

    @ngoldbaum
    Author

    If it can be changed at install time I think that would be best, there's a lot of code out there checking for INCLUDEPY: https://github.com/search?q=INCLUDEPY&type=code

  6. zanieb commented on Oct 18, 2024

    @zanieb
    Member
  7. zanieb commented on Oct 21, 2024

    @zanieb
    Member

    Opened astral-sh/uv#8429 to track this

  8. charliermarsh commented on Dec 11, 2024

    @charliermarsh
    Member

    If we rewrote INCLUDEPY at install time, would it be such that we point to an absolute path, referencing the destination to which we unpacked the Python?

  9. zanieb commented on Dec 11, 2024

    @zanieb
    Member

    I think so, yes.

  10. charliermarsh commented on Dec 17, 2024

    @charliermarsh
    Member

    This is now fixed at install-time in uv -- should we close out?

  11. zanieb commented on Dec 17, 2024

    @zanieb
    Member

    I think we may want to make it easier to apply the patches that uv does outside of uv, but perhaps we should track that separately.

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

Metadata

Metadata

Assignees

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