简体   繁体   English

使用f2py后未生成扩展模块(* .so)

[英]Extension module (*.so) is not produced after using f2py

I use Win7, and installed Anaconda for python and gfortran (MINGW) for fortran. 我使用Win7,并为python安装了Anaconda,为fortran安装了gfortran(MINGW)。

After using f2py, I cannot find a extension module file. 使用f2py后,我找不到扩展模块文件。 I tried the example in the following links: 我在以下链接中尝试了该示例:

Three ways to wrap 三种包装方式

F2PY - Calling Fortran routines from Python F2PY-从Python调用Fortran例程

If I type as follows in the Anaconda prompt, 如果在Anaconda提示符下键入以下内容,

<base> C:\Codes\F2PY> f2py -c --fcompiler=gfortran -m fib1 fib1.f

Then, fib1.cp36-win_amd64.pyd file and fib1 folder is generated. 然后, fib1.cp36-win_amd64.pyd文件和fib1文件夹。 .libs folder is located under the fib folder, and there exists libfib1.5W62YGKMVL6PD3QLPPSXTQ2OGA5LRIRQ.gfortran-win_amd64 file in the .libs folder. .libs文件夹位于下fib文件夹,存在libfib1.5W62YGKMVL6PD3QLPPSXTQ2OGA5LRIRQ.gfortran-win_amd64在文件.libs文件夹。

However, the expected extension module ( fib1.so ) is not generated. 但是,未生成预期的扩展模块( fib1.so )。

Is there anything I missed? 我有什么想念的吗?

I already checked gfortran and python are working well seprately. 我已经检查过gfortran和python分别工作良好。

C:\Codes\F2PY>f2py -c --fcompiler=gfortran -m fib1 fib1.f   
C:\Codes\F2PY>call "D:\Anaconda\Scripts\\..\python.exe" "D:\Anaconda\Scripts\\f2py.py" -c --fcompiler=gfortran -m fib1 fib1.f
Unknown vendor: "gfortran"
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, 
build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, 
build commands --fcompiler options
running build_src
build_src
building extension "fib1" sources
f2py options: []
f2py:>C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6\fib1module.c
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6
Reading fortran codes...
        Reading file 'fib1.f' (format:fix,strict)
Post-processing...
        Block: fib1
                    Block: fib
Post-processing (stage 2)...
Building modules...
       Building module "fib1"...
            Constructing wrapper function "fib"...
              fib(a,[n])
    Wrote C/API module "fib1" to file "C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6\fib1module.c"
  adding 'C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6\fortranobject.c' to sources.
  adding 'C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6' to include_dirs.
copying D:\Anaconda\lib\site-packages\numpy\f2py\src\fortranobject.c -> C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6
copying D:\Anaconda\lib\site-packages\numpy\f2py\src\fortranobject.h -> C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\src.win-amd64-3.6
build_src: building npy-pkg config files
running build_ext
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
customize MSVCCompiler
customize MSVCCompiler using build_ext
customize Gnu95FCompiler
Found executable C:\MinGW\bin\gfortran.exe
customize Gnu95FCompiler using build_ext
building 'fib1' extension
compiling C sources
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\Release\Users
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\Release\Users\6829396
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\Release\Users\6829396\AppData
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\Release\Users\6829396\AppData\Local
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\Release\Users\6829396\AppData\Local\Temp
creating C:\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_\Release\Users\6829396\AppData\Local\Temp\tmpkzx_h7w_

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\\mingw\\lib\\gcc\\mingw32\\6.3.0 /LIBPATH:c:\\mingw\\lib /LIBPATH:D:\\Anaconda\\libs /LIBPATH:D:\\Anaconda\\PCbuild\\amd64 /LIBPATH:D:\\Anaconda\\libs /LIBPATH:D:\\Anaconda\\PCbuild\\amd64 /LIBPATH:"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\ATLMFC\\lib\\x64" /LIBPATH:"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\lib\\x64" /LIBPATH:"C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\ucrt\\x64" /LIBPATH:"C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\um\\x64" /EXPORT:PyInit_fib1 C:\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\Release\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\src.win-amd64-3.6\\fib1module.obj C:\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\Release\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\src.win-amd64-3.6\\fortranobject.obj C:\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\Release\\libfib1.5W62YGKMVL6PD3QLPPSXTQ2OGA5LRIRQ.gfortran-win_amd64.lib /OUT:.\\fib1.cp36-win_amd64.pyd /IMPLIB:C:\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\Release\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\src.win-amd64-3.6\\fib1.cp36-win_amd64.lib copying C:\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs\\Release\\.libs\\libfib1.5W62YGKMVL6PD3QLPPSXTQ2OGA5LRIRQ.gfortran-win_amd64.dll -> .\\fib1\\.libs Removing build directory C:\\Users\\6829396\\AppData\\Local\\Temp\\tmpo3wc2rbs

I also use Win 7 + Anaconda + gfortran (MINGW) and had the same problem trying to wrap a subroutine distan(x,nx,nd,d) contained in a sdistan.f90 file. 我还使用Win 7 + Anaconda + gfortran(MINGW),并尝试将sdistan.f90文件中包含的subroutine distan(x,nx,nd,d)包装为相同的问题。

The command python -m numpy.f2py -c -m sdistan sdistan.f90 generated a sdistan.cp37-win_amd64.pyd file instead of a *.so module. 命令python -m numpy.f2py -c -m sdistan sdistan.f90生成了sdistan.cp37-win_amd64.pyd文件,而不是*.so模块。

After analyzing the sdistan.cp37-win_amd64.pyd file with depends.exe , I discovered that there were two unresolved external dependencies: 在使用depends.exe分析了sdistan.cp37-win_amd64.pyd文件之后,我发现存在两个未解决的外部依赖关系:

(1) the libsdistan.LD66OEXBPEJ74HMF6SZDLFFCVSPSTQVW.gfortran-win_amd64.dll DLL file that f2py places in the sdistan/.libs folder. (1) f2py放置在sdistan/.libs文件夹中的libsdistan.LD66OEXBPEJ74HMF6SZDLFFCVSPSTQVW.gfortran-win_amd64.dll DLL文件。

(2) and python3.dll (2)和python3.dll

I copied these two files (the second from C:/Anaconda3/python3.dll ) into my working directory and the problem was solved. 我将这两个文件(第二个文件从C:/Anaconda3/python3.dll )到我的工作目录中,问题已解决。

Now I can import sdistan and I can use my function as output=sdistan.distan (input arguments). 现在,我可以import sdistan并且可以将我的函数用作output=sdistan.distan (输入参数)。

I hope this can help those who find the same problem. 我希望这可以帮助那些发现相同问题的人。 It would be nice if somebody could explain and correct this (strange/miss) behavior of f2py . 如果有人可以解释并纠正f2py的这种(奇怪/未命中)的行为, 那就太好了

Thanks to everybody contributing to Stack Overflow!! 感谢所有人为堆栈溢出做出贡献!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM