Python 将f2py与distutils混合
我有一个python包“trees”,其中包含myscript.py文件,该文件使用fortran子例程 通常我用Python 将f2py与distutils混合,python,distutils,f2py,Python,Distutils,F2py,我有一个python包“trees”,其中包含myscript.py文件,该文件使用fortran子例程 通常我用 f2py -c -m calctree calctree.f90 然后我就可以做了 from trees import myscript myscript.mysub() 它利用calctree.so 如果我用distutils通过运行 python ./setup.py sdist 其中setup.py的内容是 #! /usr/bin/env python from dis
f2py -c -m calctree calctree.f90
然后我就可以做了
from trees import myscript
myscript.mysub()
它利用calctree.so
如果我用distutils通过运行
python ./setup.py sdist
其中setup.py的内容是
#! /usr/bin/env python
from distutils.core import setup
setup(name='trees',
version='0.1',
packages=['trees']
)
并在MANIFEST.in文件中指定“include trees/calctree.f90”,我可以包含.f90文件,但我不知道如何在用户计算机上使用f2py进行编译,并将.so文件放置在适当的位置。有人能帮忙吗
谢谢大家! 您想使用numpy.distutils.core模块,它有自己的设置功能。 您的setup.py应该是这样的(假设fortran文件位于名为trees的目录中)
这至少应该是一个开始 不知道内置解决方案,但您可以在调用
setup
之前自己在模块中运行该命令,然后在setup调用中包含编译后的文件。
import numpy.distutils.core
import setuptools
# setup fortran 90 extension
#---------------------------------------------------------------------------
ext1 = numpy.distutils.core.Extension(
name = 'calctree',
sources = ['trees/calc_tree.f90'],
)
# call setup
#--------------------------------------------------------------------------
numpy.distutils.core.setup(
name = 'trees',
version = '0.1',
packages = setuptools.find_packages(),
package_data = {'': ['*.f90']},
include_package_data = True,
ext_modules = [ext1],
)