0

我已经设法使用 f2py 手动包装了一组 Fortran 90 源。为此,我按照以下说明生成了签名文件:http: //docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html,我可以获得一个 .so 我可以从一些 Python 接口文件调用。

现在我想从中创建一个包,它将自动构建 Fortran 扩展。包含 Fortran 源和签名文件的文件夹中唯一添加的内容现在是 setup.py 文件,其中包含以下内容:

from numpy.distutils.core import setup, Extension
from numpy.distutils.misc_util import Configuration

DISTNAME = 'greengard'

def configuration(parent_package='',top_path=None):
    config = Configuration(DISTNAME, parent_package, top_path)
    # the Fortran sources
    f90_sources = ['_greengard.pyf'
                   'nufft1df90.f',
                   'nufft2df90.f',
                   'nufft3df90.f',
                   'next235.f',
                   'dfftpack.f',
                   ]
    config.add_extension('_greengard', f90_sources)
return config

if __name__ == "__main__":
    setup(configuration=configuration) 

然后激活一个virtualenv并尝试安装包

python setup.py install 

但最后得到以下错误:

creating build/temp.linux-x86_64-2.7/build/src.linux-x86_64-2.7/greengard
compile options: '-Ibuild/src.linux-x86_64-2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
gcc: build/src.linux-x86_64-2.7/greengard/_greengardmodule.c
gcc: build/src.linux-x86_64-2.7/fortranobject.c
compiling Fortran sources
Fortran f77 compiler: /usr/bin/gfortran -Wall -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -Wall -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -ffixed-form -fno-second-underscore -Wall -fno-second-underscore -fPIC -O3 -funroll-loops
compile options: '-Ibuild/src.linux-x86_64-2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
error: _greengard.pyfnufft1df90.f: No such file or directory

启动 setup.py 后的第一行给出:

non-existing path in '': '_greengard.pyfnufft1df90.f'

但是设置过程继续进行,Fortran 扩展似乎已编译(显示的行看起来像我通过手动运行 f2py 得到的)。

我试图从网上提供的示例中找到解决方案,但其中大多数都过于简单而无济于事。有 Python 打包经验的人可以帮我解决这个问题吗?

4

1 回答 1

0

在尝试了更多之后,我意识到我没有正确清理调用设置脚本时创建的中间“构建”目录。后者一定保留了我之前的一次失败尝试,其中共享扩展的路径设置错误。

我重试了一个空白示例,并且安装到我的 virtualenv 的站点包中已经成功。

于 2012-04-02T18:54:23.137 回答