Skip to content

Avoid passing /EXPORT:PyInit_* to MSVC for Python 3.15+ (PEP 793) #387

Open

Description

@encukou

Hello,

CPython 3.15 implements PEP 793, which adds a new module entrypoint, PyModExport_*, as an alternative to the (now soft-deprecated) PyInit_*.

Distutils/Setuptools adds PyInit_* to export_symbols, and then, on Windows, adds an /EXPORT:PyInit_* option to the linker.
This means that modules without a PyInit_* function will fail to build using Setuptools on Windows.

Luckily the workaround is easy: add a PyInit_* function (one that's backwards-compatible, or one that always raises, depending on desired behaviour 3.14 and below). However, it would be great if no workaround was necessary. Also, as of 3.15 alpha 2 there's no pressing reason for extensions to migrate to PyModExport (but this will probably change with stable ABI for free-threading).

The /EXPORT option should not be necessary. According to MSVC docs, it's preferred to use __declspec(dllexport) in the source code instead. And CPython's PyMODINIT_FUNC macro does add the __declspec(dllexport).

Would it be acceptable for setuptools to avoid adding /EXPORT (or auto-filling export_opts) when compiling for CPython 3.15+?

I'd like to solve any issues on the CPython side, ideally in the alpha period:

  • If PyMODINIT_FUNC not adding __declspec(dllexport) in some cases, let's fix that
  • PyMODINIT_FUNC being only recommended (IMO, “Porting to Python 3.15” in CPython's What's New can say that build tools are now not expected to handle this, and so PyMODINIT_FUNC or equivalent is needed in the source)

Activity

  1. rgommers commented on Dec 30, 2025

    @rgommers

    +1 this seems like a good idea. Avoiding /EXPORT completely would be nicest imho, but either way works.

    I'm not a maintainer, but I do have a decent amount of experience with this code, and I'm happy to help test/review a PR to change the >=3.15 behavior.

  2. encukou commented on Jan 13, 2026

    @encukou
    ContributorAuthor

    Thanks!
    I've sent #395 for this. If you can review or have any comments on it, it would be welcome! (Especially if you regularly use Windows and can easily test there.)

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions