Skip to content

BUG: Importing numpy.distutils.msvccompiler fails when using the latest Python 3.11 (Python 3.11.14) #29916

@riku-sakamoto

Description

@riku-sakamoto

Describe the issue:

In the recent release Python 3.11.14 (Oct 9 2025), the version of setuptools is upgraded. (see python/cpython#135396 )

Due to this change, CI tests running on Python 3.11 is currently failing.
Example: https://github.com/numpy/numpy/actions/runs/18397458439/job/52421553249

According to the documentation ( https://numpy.org/devdocs/reference/distutils_status_migration.html#numpy-setuptools-interaction ) , there seem to be two possible solutions:

  • 1: Completely erase numpy.distutils

    • The document states that "numpy.distutils has been deprecated in NumPy 1.23.0. It will be removed for Python 3.12; for Python <= 3.11 it will not be removed until 2 years after the Python 3.12 release (Oct 2025).".
      So, this seems to be a good time to remove it completely.
  • 2: set setuptools<60.0 when running CI tests on Python 3.11

    • This workaround would avoid incompatibility between numpy.distutils and recent setuptools versions.

In my opinion, option 1 seems more appropriate in the long term, but I will follow
the maintainers’ suggestion.

Reproduce the code example:

spin test -- numpy/tests/test_public_api.py::test_api_importable

Error message:

_______________________________________________________________________________ test_api_importable ________________________________________________________________________________

    def test_api_importable():
        """
        Check that all submodules listed higher up in this file can be imported
    
        Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may
        simply need to be removed from the list (deprecation may or may not be
        needed - apply common sense).
        """
        def check_importable(module_name):
            try:
                importlib.import_module(module_name)
            except (ImportError, AttributeError):
                return False
    
            return True
    
        module_names = []
        for module_name in PUBLIC_MODULES:
            if not check_importable(module_name):
                module_names.append(module_name)
    
        if module_names:
            raise AssertionError("Modules in the public API that cannot be "
                                 f"imported: {module_names}")
    
        for module_name in PUBLIC_ALIASED_MODULES:
            try:
                eval(module_name)
            except AttributeError:
                module_names.append(module_name)
    
        if module_names:
            raise AssertionError("Modules in the public API that were not "
                                 f"found: {module_names}")
    
        with warnings.catch_warnings(record=True) as w:
            warnings.filterwarnings('always', category=DeprecationWarning)
            warnings.filterwarnings('always', category=ImportWarning)
            for module_name in PRIVATE_BUT_PRESENT_MODULES:
                if not check_importable(module_name):
                    module_names.append(module_name)
    
        if module_names:
>           raise AssertionError("Modules that are not really public but looked "
                                 "public and can not be imported: "
                                 f"{module_names}")
E           AssertionError: Modules that are not really public but looked public and can not be imported: ['numpy.distutils.msvccompiler']

check_importable = <function test_api_importable.<locals>.check_importable at 0x7cd42da947c0>
module_name = 'numpy.distutils.unixccompiler'
module_names = ['numpy.distutils.msvccompiler']
w          = [<warnings.WarningMessage object at 0x7cd42bf88310>, <warnings.WarningMessage object at 0x7cd42bf8a210>, <warnings.WarningMessage object at 0x7cd42bfa8fd0>, <warnings.WarningMessage object at 0x7cd42bfa9010>]

numpy/tests/test_public_api.py:423: AssertionError
============================================================================= short test summary info ==============================================================================
FAILED numpy/tests/test_public_api.py::test_api_importable - AssertionError: Modules that are not really public but looked public and can not be imported: ['numpy.distutils.msvccompiler']
================================================================================ 1 failed in 0.24s =================================================================================

Python and NumPy Versions:

2.4.0.dev0+git20251010.d2678ee
3.11.14 (main, Oct 10 2025, 16:47:51) [GCC 11.4.0]

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions