透過 numpy.distutils
#
舊版
此子模組被視為舊版,將不再接收更新。這也可能意味著它將在未來的 NumPy 版本中被移除。 distutils
已被移除,改用 meson
,請參閱 numpy.distutils 的狀態與遷移建議。
numpy.distutils
是 NumPy 的一部分,並擴展了標準 Python distutils
模組,以處理 Fortran 原始碼和 F2PY 簽名檔,例如編譯 Fortran 原始碼、呼叫 F2PY 建構擴充模組等。
distutils 的擴展#
numpy.distutils
透過以下功能擴展了 distutils
Extension
類別引數sources
可能包含 Fortran 原始碼檔案。此外,sources
列表最多可以包含一個 F2PY 簽名檔,在這種情況下,擴充模組的名稱必須與簽名檔中使用的<modulename>
相符。假設一個 F2PY 簽名檔恰好包含一個python module
區塊。如果
sources
未包含簽名檔,則 F2PY 會用於掃描 Fortran 原始碼檔案,以建構 Fortran 程式碼的包裝器。可以使用
Extension
類別引數f2py_options
,為 F2PY 可執行檔提供額外的選項。定義了以下新的
distutils
命令build_src
以建構 Fortran 包裝器擴充模組,以及許多其他功能。
config_fc
以變更 Fortran 編譯器選項。
此外,
build_ext
和build_clib
命令也經過增強,以支援 Fortran 原始碼。執行
python <setup.py file> config_fc build_src build_ext --help
以查看這些命令的可用選項。
在建置包含 Fortran 原始碼的 Python 套件時,可以使用
build_ext
命令選項--fcompiler=<Vendor>
來選擇不同的 Fortran 編譯器。此處<Vendor>
可以是以下名稱之一(在linux
系統上)absoft compaq fujitsu g95 gnu gnu95 intel intele intelem lahey nag nagfor nv pathf95 pg vast
請參閱
numpy_distutils/fcompiler.py
以取得不同平台支援編譯器的最新列表,或執行python -m numpy.f2py -c --backend distutils --help-fcompiler