stripy icon indicating copy to clipboard operation
stripy copied to clipboard

Cannot find libgfortran, etc., on macOS when installed via pip

Open anowacki opened this issue 1 year ago • 1 comments

Thanks for maintaining stripy and apologies for the following limited bug report. I don't know much about Python packaging or wheel distribution I'm afraid.

I have tried installing stripy via pip install (and via Poetry), but when I do this I'm unable to load the dynamic libraries for the Fortran runtime:

$ pip install stripy
Collecting stripy
  Downloading stripy-2.1.0-cp38-cp38-macosx_10_14_x86_64.whl (13.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.0/13.0 MB 56.4 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.16.0 in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from stripy) (1.23.2)
Requirement already satisfied: scipy>=1.0.0 in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from stripy) (1.9.1)
Installing collected packages: stripy
Successfully installed stripy-2.1.0
In [1]: import stripy
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import stripy

File /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stripy/__init__.py:34, in <module>
     30     if _os.path.isdir(extra_dll_dir):
     31         _os.environ["PATH"] += _os.pathsep + extra_dll_dir
---> 34 from .spherical import sTriangulation
     35 from .cartesian import Triangulation
     36 from . import spherical_meshes

File /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stripy/spherical.py:21, in <module>
      1 """
      2 Copyright 2017-2019 Louis Moresi, Ben Mather
      3 
   (...)
     16 along with Stripy.  If not, see <http://www.gnu.org/licenses/>.
     17 """
     19 #!/usr/bin/python
     20 # -*- coding: utf-8 -*-
---> 21 from . import _stripack
     22 from . import _ssrfpack
     23 import numpy as np

ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stripy/_stripack.cpython-38-darwin.so, 2): Library not loaded: /usr/local/opt/gcc@10/lib/gcc/10/libgfortran.5.dylib
  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/stripy/_stripack.cpython-38-darwin.so
  Reason: image not found

It appears that the location of libgfortran (plus the other linked GCC libraries libquadmath and libgcc_s) relies on them being installed by Homebrew on macOS, whereas I have them installed elsewhere.

I don't know much about what might be possible, but I guess there are a few ways of approaching this:

  1. Require and document that these libraries need to be installed in those locations. That wouldn't be my favourite thing as I use a different package manager than Homebrew and others may do too.
  2. Distribute these libraries or rely on another package which distributes them, and code the linker path into them.
  3. Use install_name_tool to fix the linker paths (with @rpath?)

I'm happy to help diagnose things if that helps.

anowacki avatar Sep 08 '22 14:09 anowacki