从子文件夹导入Python - Fortran .so里面.so来自f2py - ImportError(找不到图像)

时间:2014-12-04 16:18:49

标签: python import linker fortran f2py

我正在导入位于子文件夹'Fortran_Interface'中的 Python库'Interface'(用f2py包装):

import Interface

'Interface.so'被编译为链接到Fortran lib'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'与相对pat h链接到'libsolver.so',哪个python使用上面的目录

我很感激有关如何解决这个问题的任何想法。使用绝对路径编译.so是不行的,以及从我的主脚本调用库目录中的python脚本...

修改: 使用从我的python脚本文件夹到lib solver.so的符号链接,它可以工作。

1 个答案:

答案 0 :(得分:0)

(问题由OP解决并在解决方案中进行了编辑。请参阅Question with no answers, but issue solved in the comments (or extended in chat)

OP写道:

  

使用从我的python脚本文件夹到lib solver.so的符号链接,它可以工作。