Setting The Fortran Compiler In F2py
I am trying to run the f2py example to create the compiled extension module¶: # import os # os.environ['CC'] = 'gcc' # os.environ['CXX'] = 'g++' # Using post-0.2.2 scipy_distuti
Solution 1:
Per the tutorial docs, an easy way to use f2py is to run from the command line
f2py -c -m addadd.f
This creates the module file add.so
(or add.pyd
, depending on your OS), which can be imported into Python scripts with
import add
provided add.so
is in a directory listed in sys.path
.
Solution 2:
f2py is now maintained as part of numpy. Altering your example as follows compiles just fine.
# import os# os.environ["CC"] = "gcc"# os.environ["CXX"] = "g++"# Using post-0.2.2 scipy_distutils to display fortran compilersfrom numpy.distutils.fcompiler import new_fcompiler
compiler = new_fcompiler() # or new_fcompiler(compiler='intel')
compiler.dump_properties()
#Generate add.f wrapperfrom numpy import f2py
withopen("add.f") as sourcefile:
sourcecode = sourcefile.read()
print'Fortran code'print sourcecode
# f2py.compile(sourcecode, modulename='add', extra_args = '--compiler=gnu --fcompiler=g$
f2py.compile(sourcecode, modulename='add', extra_args = '--fcompiler=gfortran')
# f2py.compile(sourcecode, modulename='add')import add
Post a Comment for "Setting The Fortran Compiler In F2py"