Search code examples
pythonmodulefortrancompiled.so

Python importing compiled functions


I've downloaded a 'custom' fisher exact test that is based on the R function that was in turn compiled from C/FORTRAN (source)

The package includes the main file/function (Fisher.py) which in turn imports functions from fexact, asa159 and asa205 files. The issue is that these files are a C shared object i.e. have a .so extension and so python does not recognize them when importing; giving an error.

  ...customlib/fexact.so, 2): no suitable image found.  Did find:
  .../customlib/fexact.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00

Not sure how to handle this.

Fisher.py contains:

  import customlib.fexact as f
  from customlib.fexact import fisher_exact as f_exact
  from customlib.asa159 import rcont2
  from customlib.asa205 import enum as rcont

customlib folder contains: 1. an __init__ 2. asa159.so 3. asa205.so 4. fexact.so


Solution

  • Run the recompile script provided in the package. The libraries are compiled for the system the original author was using and are not portable across systems. You might need to update the call of f2py to point to the correct version for your use.