【发布时间】:2015-02-02 14:46:20
【问题描述】:
我正在导入位于子文件夹“Fortran_Interface”(使用 f2py 包装)中的 Python 库“接口”:
import Interface
“Interface.so”被编译为链接到 Fortran 库“libsolver.so”。编译是用命令完成的
gfortran -shared -O2 -o libsolver.so -fPIC Solver/Module_Solver.f90
f2py -c --fcompiler=gfortran -L. -I. -lsolver -m Interface Interface/Module_Interface.f90
我得到了错误
ImportError: dlopen(/Users/gmueller/Workspace/PySpinX_G/Fortran_Interface/Interface.so, 2): Library not loaded: libsolver.so
Referenced from: /Users/gmueller/Workspace/PySpinX_G/Fortran_Interface/Interface.so
Reason: image not found
我可以从库目录中导入库,但不能从上面的文件夹中导入。在我看来,这似乎是因为“Interface.so”通过相对 path 链接到“libsolver.so”,python 从上面的目录中使用。
如果您有任何关于如何解决此问题的想法,我将不胜感激。用绝对路径编译 .so 不起作用,以及从我的主脚本调用库目录中的 python 脚本......
编辑: 通过从我的 python 脚本文件夹到 lib solver.so 的符号链接,它可以工作。
【问题讨论】:
标签: python import linker fortran f2py