← 返回命令列表

Linux command

f2py 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Generate Python wrapper

f2py -c [module.f90] -m [module_name]

Create signature file

f2py [module.f90] -h [module.pyf]

Build with specific

f2py -c --fcompiler=[gfortran] [module.f90] -m [module_name]

Link external libraries

f2py -c [module.f90] -m [module_name] -l[blas]

Show available compilers

f2py --help-fcompiler

说明

f2py (Fortran to Python) is a NumPy tool that creates Python bindings for Fortran code. It generates wrapper modules that allow calling Fortran subroutines and functions directly from Python. The tool automatically handles type conversion between Python/NumPy arrays and Fortran arrays. It parses Fortran source code or signature files to determine interfaces, then generates C wrapper code compiled into a Python extension module. f2py enables using high-performance Fortran libraries in Python scientific computing workflows without rewriting existing code.

参数

-c
Compile and build extension module.
-m _NAME_
Set module name.
-h _FILE_
Generate signature file.
--fcompiler _NAME_
Specify Fortran compiler.
-l _LIBRARY_
Link with library.
-L _PATH_
Library search path.
-I _PATH_
Include search path.
--help-fcompiler
List available Fortran compilers.
--help
Display help information.

FAQ

What is the f2py command used for?

f2py (Fortran to Python) is a NumPy tool that creates Python bindings for Fortran code. It generates wrapper modules that allow calling Fortran subroutines and functions directly from Python. The tool automatically handles type conversion between Python/NumPy arrays and Fortran arrays. It parses Fortran source code or signature files to determine interfaces, then generates C wrapper code compiled into a Python extension module. f2py enables using high-performance Fortran libraries in Python scientific computing workflows without rewriting existing code.

How do I run a basic f2py example?

Run `f2py -c [module.f90] -m [module_name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c do in f2py?

Compile and build extension module.