10BC0 BUG: `f2py` still attempts to import `numpy.distutils` on Python 3.12 when `--fcompiler` option is specified. · Issue #24838 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: f2py still attempts to import numpy.distutils on Python 3.12 when --fcompiler option is specified. #24838

@whophil

Description

@whophil

Describe the issue:

f2py implements some logic to use the meson backend automatically on Python 3.12, where numpy.distutils no longer exists.

However, when calling f2py with the --fcompiler option, numpy.distutils is still imported, which raises ImportError when using running f2py with Python 3.12. This is due to the logic in these lines: https://github.com/numpy/numpy/blob/main/numpy/f2py/f2py2e.py#L608-L610

If the --fcompiler is not supported with the meson backend, perhaps a more useful error message could be thrown earlier?

Reproduce the code example:

f2py --fcompiler=gfortran -c -m

Error message:

Cannot use distutils backend with Python 3.12, using meson backend instead.Traceback (most recent call last):
  File "/Users/phil/miniforge3/envs/meson/bin/f2py", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/phil/miniforge3/envs/meson/lib/python3.12/site-packages/numpy/f2py/f2py2e.py", line 732, in main
    run_compile()
  File "/Users/phil/miniforge3/envs/meson/lib/python3.12/site-packages/numpy/f2py/f2py2e.py", line 610, in run_compile
    from numpy.distutils import fcompiler
ModuleNotFoundError: No module named 'numpy.distutils'

Runtime information:

>>> import sys, numpy; print(numpy.__version__); print(sys.version); print(numpy.show_runtime())
1.26.0
3.12.0rc3 | packaged by conda-forge | (main, Sep 26 2023, 22:14:47) [Clang 15.0.7 ]
WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information
[{'numpy_version': '1.26.0',
  'python': '3.12.0rc3 | packaged by conda-forge | (main, Sep 26 2023, '
            '22:14:47) [Clang 15.0.7 ]',
  'uname': uname_result(system='Darwin', node='Phillips-MacBook-Pro.local', release='22.5.0', version='Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000', machine='x86_64')},
 {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3', 'SSSE3'],
                      'found': ['SSE41', 'POPCNT', 'SSE42'],
                      'not_found': ['AVX',
                                    'F16C',
                                    'FMA3',
                                    'AVX2',
                                    'AVX512F',
                                    'AVX512CD',
                                    'AVX512_KNL',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}}]

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0