2014-03-03 42 views
2

我想爲我的一個使用f2py的fortran程序打包。我的FORTRAN程序使用外部庫,當我嘗試將它們連接我得到一個錯誤說:Python numpy/f2py鏈接庫

gfortran:f77: /var/folders/46/l1mrxgls07s6tpwb6tgpvhpr0000gn/T/tmpPCM7Ne/src.macosx-10.9-intel-2.7/progs-f2pywrappers.f 
Traceback (most recent call last): 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/bin/f2py", line 24, in <module> 
    main() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/f2py/f2py2e.py", line 588, in main 
    run_compile() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/f2py/f2py2e.py", line 574, in run_compile 
    setup(ext_modules = [ext]) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/core.py", line 186, in setup 
    return old_setup(**new_attr) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup 
    dist.run_commands() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands 
    self.run_command(cmd) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command 
    cmd_obj.run() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/command/build.py", line 37, in run 
    old_build.run(self) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run 
    self.run_command(cmd_name) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command 
    self.distribution.run_command(command) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command 
    cmd_obj.run() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/command/build_ext.py", line 232, in run 
    self.build_extensions() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py", line 448, in build_extensions 
    self.build_extension(ext) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/command/build_ext.py", line 425, in build_extension 
    build_temp=self.build_temp,**kws) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 691, in link_shared_object 
    extra_preargs, extra_postargs, build_temp, target_lang) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/fcompiler/__init__.py", line 643, in link 
    libraries) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/ccompiler.py", line 571, in gen_lib_options 
    runtime_library_dirs, libraries) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 1086, in gen_lib_options 
    lib_file = compiler.find_library_file([lib_dir], lib_name) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 777, in find_library_file 
    raise NotImplementedError 

所以,它看起來像我從Python庫中獲取從文件ccompiler.py錯誤。

該錯誤對應的代碼文件中的以下行:

def find_library_file (self, dirs, lib, debug=0): 
     """Search the specified list of directories for a static or shared 
     library file 'lib' and return the full path to that file. If 
     'debug' true, look for a debugging version (if that makes sense on 
     the current platform). Return None if 'lib' wasn't found in any of 
     the specified directories. 
     """ 
     raise NotImplementedError 

我有點困惑什麼,我需要做的,因爲我是新來的Python來解決這個問題。似乎這種方法尚未實施。我只需要執行它?我究竟如何實現這一目標?我是否需要重建f2py可執行文件以進行此更改?如果是這樣,我將如何做到這一點?

謝謝!

+0

我有同樣的問題:我的f2py命令是:'f2py -lc:/ pytm/lib -m main -c main.f90'我按照這裏的說明操作:https://modelingguru.nasa.gov/docs/ DOC-2343 – JohnE

+0

的確,這是一種抽象方法(請參閱https://hg.python.org/cpython/file/648dcafa7e5f/Lib/distutils/ccompiler.py#l24),我想f2py或numpy.distutils必須實現它某處。 – astrojuanlu

+0

我有完全相同的問題。我正在嘗試按照本指南安裝scipy:https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl並引發此錯誤。你是如何解決這個問題的? – arnstrm

回答

1

這裏沒有回答這個問題,但它確實提供了一種解決方法(只需直接引用所有* .o文件,而不是將它們放入庫中)。而且,這僅僅是解釋f2py一些事情的一個很棒的帖子。

Including a compiled module in module that is wrapped with f2py (Minimum working example)?

f2py -c --fcompiler=gfortran -I. libtest.o -m Main main.f90

,如果你的庫是基於一個單一的文件,將工作。如果您的庫(更可能)基於多個文件,則只需包含全套* .o名稱即可。

+0

示例如何使用* .o文件進行操作可以在[這裏]找到(http://stackoverflow.com/a/33612970/2969529) –