Re: How to handle ModuleNotFoundError: No module named 'distutils.msvccompiler' on Mac OSX (Intel) using f2py?

Bill Ross <[email protected]> Sun, 04 Jan 2026 18:23:22 -0800
Newsgroups gmane.comp.python.numeric.general
Organization Phobrain
Message-ID <[email protected]>
Uninformed debugging:

> build_backend = f2py_build_generator(backend_key)

Can you inspect that backend_key? It seems  like it could be 'key' to 
choosing the wrong back end.

Bill

--

Phobrain.com

On 2026-01-04 17:18, Samuel H Dupree Jr wrote:

> I am resurrecting a Python program I wrote a few years under Python 
> 3.9. I'm presently:
> 
> * Running Python 3.11 under Mac OSX Sequoia (ver. 15.7.1)
> * Using NumPy version 1.26.4
> * Running on an Intel (x86-64) Mac Pro Desktop (2019)
> *
> 
> The program uses a Fortran 77 subroutine that was wrapped using f2py 
> when I running Python 3.9. However, when I attempt to wrap that same 
> subroutine (the source code is attached to this note) using f2py in 
> Python 3.11, I get the following error message.
> 
> (base) user@Mac-Pro accgravityfiled_builder_f2py % _f2py -c 
> accgravityfield.f  -m accgravityfield _
> Traceback (most recent call last):
> File "/Users/user/opt/anaconda3/bin/f2py", line 8, in <module>
> sys.exit(main())
> ^^^^^^
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/f2py/f2py2e.py", 
> line 766, in main
> run_compile()
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/f2py/f2py2e.py", 
> line 594, in run_compile
> build_backend = f2py_build_generator(backend_key)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/f2py/_backends/__init__.py", 
> line 6, in f2py_build_generator
> from ._distutils import DistutilsBackend
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/f2py/_backends/_distutils.py", 
> line 3, in <module>
> from numpy.distutils.core import setup, Extension
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/distutils/core.py", 
> line 24, in <module>
> from numpy.distutils.command import config, config_compiler, \
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/distutils/command/config.py", 
> line 19, in <module>
> from numpy.distutils.mingw32ccompiler import generate_manifest
> File 
> "/Users/user/opt/anaconda3/lib/python3.11/site-packages/numpy/distutils/mingw32ccompiler.py", 
> line 27, in <module>
> from distutils.msvccompiler import get_build_version as 
> get_build_msvc_version
> ModuleNotFoundError: No module named 'distutils.msvccompiler'
> (base) user@Mac-Pro accgravityfiled_builder_f2py %
> 
> As for gfortran is concerned:
> 
> (base) user@Mac-Pro accgravityfiled_builder_f2py % gfortran -v
> Using built-in specs.
> COLLECT_GCC=gfortran
> COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/15.2.0/bin/../libexec/gcc/x86_64-apple-darwin24/15/lto-wrapper
> Target: x86_64-apple-darwin24
> Configured with: ../configure --prefix=/usr/local/opt/gcc 
> --libdir=/usr/local/opt/gcc/lib/gcc/current --disable-nls 
> --enable-checking=release --with-gcc-major-version-only 
> --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-15 
> --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr 
> --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl 
> --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 15.2.0' 
> --with-bugurl=https://github.com/Homebrew/homebrew-core/issues 
> --with-system-zlib --build=x86_64-apple-darwin24 
> --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk
> Thread model: posix
> Supported LTO compression algorithms: zlib zstd
> gcc version 15.2.0 (Homebrew GCC 15.2.0)
> (base) user@Mac-Pro accgravityfiled_builder_f2py %
> 
> I have two questions:
> 
> * Why is f2py in a Mac OSX Intel based environment attempting to import 
> '_distutils.msvccompiler_' that is required for Windows' environment 
> only?
> * What do I need to do to eliminate this problem?
> 
> Any thoughts?
> 
> Sam Dupree
> 
> _______________________________________________
> NumPy-Discussion mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3//lists/numpy-discussion.python.org
> Member address: [email protected]

_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]