I'm trying to install a Python package that relies on extensions built from Fortran 90 using f2py, but I get the following error:

error: f90 not supported by GnuFCompiler needed for source_file.f90

I have both gfortran and g77 installed, what is going wrong?


By default, f2py prefers the GNU Fortran 77 compiler --fcompiler=gnu over the GNU Fortran 95 compiler --fcompiler=gnu95. If you have both g77 and gfortran on your path, then f2py will, use g77, which cannot build Fortran 90 extensions.

If you would prefer for numpy to use gfortran over g77, you can either pass the --fcompiler=gnu95 flag to setup.py when building your code, or you can modify your numpy installation's numpy/distutils/fcompiler/__init__.py file [*] from:

_default_compilers = (
# sys.platform mappings
('win32', ('gnu','intelv','absoft','compaqv','intelev','gnu95','g95',
           'intelvem', 'intelem')),
('cygwin.*', ('gnu','intelv','absoft','compaqv','intelev','gnu95','g95')),
('linux.*', ('gnu','intel','lahey','pg','absoft','nag','vast','compaq',
('darwin.*', ('nag', 'absoft', 'ibm', 'intel', 'gnu', 'gnu95', 'g95', 'pg')),
('sunos.*', ('sun','gnu','gnu95','g95')),
('irix.*', ('mips','gnu','gnu95',)),
('aix.*', ('ibm','gnu','gnu95',)),
# os.name mappings
('posix', ('gnu','gnu95',)),
('nt', ('gnu','gnu95',)),
('mac', ('gnu','gnu95','pg')),


_default_compilers = (
# sys.platform mappings
('win32', ('gnu95','intelv','absoft','compaqv','intelev','gnu','g95',
           'intelvem', 'intelem')),
('cygwin.*', ('gnu95','intelv','absoft','compaqv','intelev','gnu','g95')),
('linux.*', ('gnu95','intel','lahey','pg','absoft','nag','vast','compaq',
('darwin.*', ('nag', 'absoft', 'ibm', 'intel', 'gnu95', 'gnu', 'g95', 'pg')),
('sunos.*', ('sun','gnu95','gnu','g95')),
('irix.*', ('mips','gnu95','gnu',)),
('aix.*', ('ibm','gnu95','gnu',)),
# os.name mappings
('posix', ('gnu95','gnu',)),
('nt', ('gnu95','gnu',)),
('mac', ('gnu95','gnu','pg')),

This will prioritize gfortran over g77, allowing you to build Fortran 90 extensions for your Python code using f2py.

[*] If you've never modified an installed Python module before, you will probably we wondering where to find it. From your Python prompt:

import numpy; print numpy.__file__

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.