在Windows上使用f2py构建64位Python扩展 [英] Building 64-bit Python extensions with f2py on Windows

查看:312
本文介绍了在Windows上使用f2py构建64位Python扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Numpy的f2py.py脚本从Fortran源构建Python扩展.我正在按照 http://www.scipy.org/F2PY_Windows (网络归档).我的系统是Windows 7 64位,主要使用Python 2.7.3 [MSC v.1500 64位(AMD64)].我有Numpy-MKL 1.7.1,来自 http://www.lfd.uci .edu/〜gohlke/pythonlibs/#numpy

I'm attempting to build a Python extension from Fortran source using Numpy's f2py.py script. I'm following the steps from http://www.scipy.org/F2PY_Windows (web archive). My system is Windows 7 64-bit, and I primarily use Python 2.7.3 [MSC v.1500 64 bit (AMD64)]. I have Numpy-MKL 1.7.1, from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

这是我尝试过的:

  1. 选择一个Fortran编译器.由于我使用的是64位Python,因此需要64位Fortran编译器.在 MinGW-w64 中,我尝试了一些个人版本.
  2. 打开一个新的cmd.exe shell,并编辑提取GCC编译器的路径,即:
    • set PATH=%PATH%;c:\gnu\mingw64\bin
    • set C_INCLUDE_PATH=C:\gnu\mingw64\include
  1. Choose a Fortran compiler. Since I'm using 64-bit Python, a 64-bit Fortran compiler is required. From MinGW-w64, I've tried a few of the personal builds.
  2. Open a new cmd.exe shell, and edit the path to where I extracted the GCC compilers, i.e.:
    • set PATH=%PATH%;c:\gnu\mingw64\bin
    • set C_INCLUDE_PATH=C:\gnu\mingw64\include

尝试使用以下命令构建f2py.py:

Try the f2py.py build with this command:

C:\Python27\python.exe C:\Python27\Scripts\f2py.py -c --fcompiler=gnu95 --compiler=mingw32 -lmsvcr90 -m foo foo.f90

输出为(消除<--snip-->处的噪声线):

The output is (removing noise lines at <--snip-->):

running build
<--snip-->
Reading fortran codes...
        Reading file 'foo.f90' (format:free)
Post-processing...
        Block: foo
                        Block: hello
Post-processing (stage 2)...
Building modules...
        Building module "foo"...
                Constructing wrapper function "hello"...
                  hello()
        Wrote C/API module "foo" to file "c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7\foomodule.c"
  adding 'c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7\fortranobject.c' to sources.
  adding 'c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7' to include_dirs.
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\mtoews\appdata\local\temp\tmpjr6qop\src.win-amd64-2.7
build_src: building npy-pkg config files
running build_ext
Looking for python27.dll
Building import library (arch=AMD64): "C:\Python27\libs\libpython27.a" (from C:\Windows\system32\python27.dll)
Building msvcr library: "C:\Python27\libs\libmsvcr90.a" (from C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll)
Cannot build msvcr library: "msvcr90d.dll" not found
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
customize Gnu95FCompiler
Found executable c:\gnu\mingw64\bin\gfortran.exe
Found executable c:\gnu\mingw64\bin\gfortran.exe
Traceback (most recent call last):
  File "C:\Python27\Scripts\f2py.py", line 24, in <module>
    main()
<--snip-->
  File "C:\Python27\lib\site-packages\numpy\distutils\fcompiler\gnu.py", line 331, in get_libraries
    raise NotImplementedError("Only MS compiler supported with gfortran on win64")
NotImplementedError: Only MS compiler supported with gfortran on win64

请注意,第一次运行此文件时,会在C:\Python27\libs中构建三个新文件:

Note that the first time this is run, three new files are build in C:\Python27\libs:

  • libmsvcr90.a
  • libpython27.a
  • python27.def
  • libmsvcr90.a
  • libpython27.a
  • python27.def

我还需要安装其他东西吗?我是否需要为f2py提供其他选项?更笼统地说,是否可以从GNU编译器为MSVC构建Python扩展?

Do I need to install anything else? Do I need to provide other options to f2py? More generally speaking, it possible to build an extension for MSVC-build Python from GNU compilers?

推荐答案

似乎解决方案是仅注释掉异常行.参见此博客文章.

It seems that the solution is to just comment out the exception line. See this blog post.

这篇关于在Windows上使用f2py构建64位Python扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆