admin管理员组

文章数量:1399474

When compiling with gfortran and f2py and importing the *.so in jupyter I get: Symbol not found: __gfortran_compare_string

I am running on an iMac with Ventura 13.6.9 and python and gcc installed with Macports. I tried with gcc11, gcc12, gcc14, python3.11, 3.12, and 3.13, same problem. To date the only python I can use with f2py is 3.7 !!!!!

Here is a minimalist version of the problem:

Code "Trial.f":

  program Trial
   call Check()
  end
  subroutine Check()
    print *, 'Hello World'
   return
  end

Compilation: two option, but they give the same result:

f2py --fcompiler=/opt/local/bin/gfortran-mp-14 -L/opt/local/lib/gcc14 -c -m Trial_Py Trial.f

f2py -c -m Trial_Py Trial.f

For f2py to find the gfortran I also have to create a symbolic link in a "my_bin" folder in my PATH so that: gfortran -> /opt/local/bin/gfortran-mp-14 Without that f2py doesn't find gfortran-mp-14 inspite of /opt&local/bin being in my PATH

Importing it into jupyter, with python 3.12:

[1] import Trial_Py

ImportError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import Trial_Py

ImportError: dlopen(/Users/dany/TMP/Trial_Py.cpython-312-darwin.so, 0x0002): Symbol not found: __gfortran_set_args Referenced from: <6F42A5D4-A263-370E-9CA6-B0968DE5C17D> /Users/dany/TMP/Trial_Py.cpython-312-darwin.so Expected in: unknown

Here are the libgfortran I have, all pointing to the first one:

-rwxr-xr-x 1 root wheel 1778544 Aug 12 2024 /opt/local/lib/libgcc/libgfortran.5.dylib

lrwxr-xr-x 1 root wheel 19 Aug 12 2024 /opt/local/lib/libgcc/libgfortran.dylib -> libgfortran.5.dylib

lrwxr-xr-x 1 root wheel 19 Aug 12 2024 /opt/local/lib/gcc14/libgfortran.dylib -> libgfortran.5.dylib

lrwxr-xr-x 1 root wheel 41 Aug 12 2024 /opt/local/lib/gcc14/libgfortran.5.dylib -> /opt/local/lib/libgcc/libgfortran.5.dylib

and the environment variable LIBRARY_PATH is empty

When compiling with gfortran and f2py and importing the *.so in jupyter I get: Symbol not found: __gfortran_compare_string

I am running on an iMac with Ventura 13.6.9 and python and gcc installed with Macports. I tried with gcc11, gcc12, gcc14, python3.11, 3.12, and 3.13, same problem. To date the only python I can use with f2py is 3.7 !!!!!

Here is a minimalist version of the problem:

Code "Trial.f":

  program Trial
   call Check()
  end
  subroutine Check()
    print *, 'Hello World'
   return
  end

Compilation: two option, but they give the same result:

f2py --fcompiler=/opt/local/bin/gfortran-mp-14 -L/opt/local/lib/gcc14 -c -m Trial_Py Trial.f

f2py -c -m Trial_Py Trial.f

For f2py to find the gfortran I also have to create a symbolic link in a "my_bin" folder in my PATH so that: gfortran -> /opt/local/bin/gfortran-mp-14 Without that f2py doesn't find gfortran-mp-14 inspite of /opt&local/bin being in my PATH

Importing it into jupyter, with python 3.12:

[1] import Trial_Py

ImportError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import Trial_Py

ImportError: dlopen(/Users/dany/TMP/Trial_Py.cpython-312-darwin.so, 0x0002): Symbol not found: __gfortran_set_args Referenced from: <6F42A5D4-A263-370E-9CA6-B0968DE5C17D> /Users/dany/TMP/Trial_Py.cpython-312-darwin.so Expected in: unknown

Here are the libgfortran I have, all pointing to the first one:

-rwxr-xr-x 1 root wheel 1778544 Aug 12 2024 /opt/local/lib/libgcc/libgfortran.5.dylib

lrwxr-xr-x 1 root wheel 19 Aug 12 2024 /opt/local/lib/libgcc/libgfortran.dylib -> libgfortran.5.dylib

lrwxr-xr-x 1 root wheel 19 Aug 12 2024 /opt/local/lib/gcc14/libgfortran.dylib -> libgfortran.5.dylib

lrwxr-xr-x 1 root wheel 41 Aug 12 2024 /opt/local/lib/gcc14/libgfortran.5.dylib -> /opt/local/lib/libgcc/libgfortran.5.dylib

and the environment variable LIBRARY_PATH is empty

Share Improve this question edited Mar 29 at 2:01 Dany Page asked Mar 25 at 17:59 Dany PageDany Page 113 bronze badges 3
  • It seems that you have a mess of various versions of compilers. The gfortran versions do not all use the same runtime library version. Please show the exact steps you are doing when compiling and importing and your configuration of environment paths to libraries, see How to Ask and minimal reproducible example. – Vladimir F Героям слава Commented Mar 26 at 6:15
  • I added a minimalistic example of the problem. I only have de gcc14 from MacPorts installed (and maybe a Macos compiler from the command-line-tools, but I don't know about it) – Dany Page Commented Mar 28 at 22:13
  • I uninstalled all gcc I had and re-installed only gcc14 – Dany Page Commented Mar 30 at 17:09
Add a comment  | 

1 Answer 1

Reset to default 0

Jupyter Server often runs in its own conda environment, so the paths into its own environment has priority. In addition, it is possible that the IPython kernel does not have a path to /opt/local/lib at all.

It is a reasonable practice to install the gfortran compiler in the used conda environment.

Try the Notebook example with your subroutine Check() on Google Colab:
https://colab.research.google/drive/1twLnKLMvgmXHK7fuuodJ-agYj2edEsn7?usp=sharing

P.S.

It does not affect the loading of the module, but it should be noted. Using print in f2py code at the same time as print in Python code can work a bit strangely (depend Numpy&IPython versions), especially in Notebook, due to the lack of synchronisation of output buffers and/or redirect output.

本文标签: jupyterSymbol not found gfortrancomparestringStack Overflow