gpt4 book ai didi

numpy - 在 Windows 上使用 f2py 构建 64 位 Python 扩展

转载 作者:行者123 更新时间:2023-12-01 16:30:30 25 4
gpt4 key购买 nike

我正在尝试使用 Numpy 的 f2py.py 从 Fortran 源代码构建 Python 扩展脚本。我正在按照 http://www.scipy.org/F2PY_Windows 中的步骤操作(web archive)。我的系统是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

这是我尝试过的:

  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
  3. 尝试 f2py.py使用此命令构建:

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

输出为(删除 <--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中构建三个新文件。 :

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

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

最佳答案

看来解决方案就是注释掉异常行。看这个blog post .

关于numpy - 在 Windows 上使用 f2py 构建 64 位 Python 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16929544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com