Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
whophil opened this issue Sep 30, 2023 · 2 comments · Fixed by #25123

Comments

@whophil
Copy link

whophil commented Sep 30, 2023

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

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Oct 1, 2023
@charris
Copy link
Member

charris commented Oct 1, 2023

@HaoZeke Ping.

@whophil Is this in NumPy 1.26.0?

@HaoZeke
Copy link
Member

HaoZeke commented Oct 1, 2023

Yeah, sorry, this should be simple to close, it should throw. @whophil, the correct usage now (should be documented as well) is to set the FC variable (some documentation here), e.g.:

FC=gfortran f2py -c -m

This will ensure meson picks up the compiler correctly.

HaoZeke added a commit to HaoZeke/numpy that referenced this issue Nov 12, 2023
@charris charris added this to the 1.26.3 release milestone Nov 12, 2023
HaoZeke added a commit to HaoZeke/numpy that referenced this issue Nov 19, 2023
HaoZeke added a commit to HaoZeke/numpy that referenced this issue Nov 19, 2023
HaoZeke added a commit to HaoZeke/numpy that referenced this issue Nov 22, 2023
@charris charris removed this from the 1.26.3 release milestone Dec 18, 2023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Dec 18, 2023
charris pushed a commit to charris/numpy that referenced this issue Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants