aburrell / apexpy

A Python wrapper for Apex coordinates
MIT License
34 stars 25 forks source link

Question: Import error: Library not loaded: @rpath/libgfortran.5.dylib Reason: image not found #69

Closed jpreistad closed 2 years ago

jpreistad commented 3 years ago

Dear maintainers, This issue is similar to #10 . I am running Mac OS Big Sur v. 11.2.3. I have used homebrew to install gcc (brew install gcc).

(base) jone@x86_64-apple-darwin13 ~ % gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I have also installed Anaconda (python 3.8.5) and the libgfortran conda package (conda install -c conda-forge libgfortran). Not sure if this is a good strategy. Apexpy was then installed with pip install apexpy without any errors.

Similar to #10 , I get this error when importing Apexpy:

In [1]: import apexpy
/Users/jone/anaconda3/lib/python3.8/site-packages/apexpy/apex.py:16: UserWarning: fortranapex module could not be imported, so apexpy probably won't work.  Make sure you have a gfortran compiler. Wheels installation assumes your compiler lives in /opt/local/bin
  warnings.warn("".join(["fortranapex module could not be imported, so ",
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-20ab8dd999be> in <module>
----> 1 import apexpy

~/anaconda3/lib/python3.8/site-packages/apexpy/__init__.py in <module>
      1 from __future__ import absolute_import, division, print_function
      2 
----> 3 from .apex import Apex, ApexHeightError
      4 from . import helpers
      5 

~/anaconda3/lib/python3.8/site-packages/apexpy/apex.py in <module>
     18                            "a gfortran compiler. Wheels installation ",
     19                            "assumes your compiler lives in /opt/local/bin"]))
---> 20     raise err
     21 
     22 # make sure invalid warnings are always shown

~/anaconda3/lib/python3.8/site-packages/apexpy/apex.py in <module>
     12 # Below try..catch required for autodoc to work on readthedocs
     13 try:
---> 14     from . import fortranapex as fa
     15 except ImportError as err:
     16     warnings.warn("".join(["fortranapex module could not be imported, so ",

ImportError: dlopen(/Users/jone/anaconda3/lib/python3.8/site-packages/apexpy/fortranapex.cpython-38-darwin.so, 2): Library not loaded: @rpath/libgfortran.5.dylib
  Referenced from: /Users/jone/anaconda3/lib/python3.8/site-packages/apexpy/fortranapex.cpython-38-darwin.so
  Reason: image not found

So apparently there is an issue related to finding libgfortran. I can see that the file 'libgfortran.5.dylib' is found at two different locations:

/usr/local/lib/gcc/10/
/usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10/ 

Also, anaconda installed a different version:

(base) jone@x86_64-apple-darwin13 10 % mdfind -name libgfortran.3.dylib
/Users/jone/anaconda3/lib/libgfortran.3.dylib

According to the warning message in line 16 in apex.py, the gfortran compiler should live in a static location (/opt/local/bin). I have not figured out what @rpath refer to in the error above, but it may be the same location. I have tried to make symbolic links and copying the above located file to this location, with no luck.

There is likely a simple solution to this, but I have unfortunately not been able to dig much deeper into this material. Any help here would be very much appreciated! I have no reason for claiming this to be a bug in Apexpy at this point.

Thanks, -Jone

asreimer commented 3 years ago

Would you be able to try the instructions in the documentation: https://apexpy.readthedocs.io/en/latest/installation.html#pypi

Specifically, the instructions that include the --no-binary option in the pip command?

On Mon, Mar 22, 2021, 03:11 jpreistad @.***> wrote:

Dear maintainers, This issue is similar to #10 https://github.com/aburrell/apexpy/issues/10 . I am running Mac OS Big Sur v. 11.2.3. I have used homebrew to install gcc (brew install gcc).

(base) @.***_64-apple-darwin13 ~ % gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I have also installed Anaconda (python 3.8.5) and the libgfortran conda package (conda install -c conda-forge libgfortran). Not sure if this is a good strategy. Apexpy was then installed with pip install apexpy without any errors.

Similar to #10 https://github.com/aburrell/apexpy/issues/10 , I get this error when importing Apexpy:

In [1]: import apexpy /Users/jone/anaconda3/lib/python3.8/site-packages/apexpy/apex.py:16: UserWarning: fortranapex module could not be imported, so apexpy probably won't work. Make sure you have a gfortran compiler. Wheels installation assumes your compiler lives in /opt/local/bin warnings.warn("".join(["fortranapex module could not be imported, so ",

ImportError Traceback (most recent call last)

in ----> 1 import apexpy ~/anaconda3/lib/python3.8/site-packages/apexpy/__init__.py in 1 from __future__ import absolute_import, division, print_function 2 ----> 3 from .apex import Apex, ApexHeightError 4 from . import helpers 5 ~/anaconda3/lib/python3.8/site-packages/apexpy/apex.py in 18 "a gfortran compiler. Wheels installation ", 19 "assumes your compiler lives in /opt/local/bin"])) ---> 20 raise err 21 22 # make sure invalid warnings are always shown ~/anaconda3/lib/python3.8/site-packages/apexpy/apex.py in 12 # Below try..catch required for autodoc to work on readthedocs 13 try: ---> 14 from . import fortranapex as fa 15 except ImportError as err: 16 warnings.warn("".join(["fortranapex module could not be imported, so ", ImportError: dlopen(/Users/jone/anaconda3/lib/python3.8/site-packages/apexpy/fortranapex.cpython-38-darwin.so, 2): Library not loaded: @rpath/libgfortran.5.dylib Referenced from: /Users/jone/anaconda3/lib/python3.8/site-packages/apexpy/fortranapex.cpython-38-darwin.so Reason: image not found So apparently there is an issue related to finding libgfortran. I can see that the file 'libgfortran.5.dylib' is found at two different locations: /usr/local/lib/gcc/10/ /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10/ Also, anaconda installed a different version: (base) ***@***.***_64-apple-darwin13 10 % mdfind -name libgfortran.3.dylib /Users/jone/anaconda3/lib/libgfortran.3.dylib According to the warning message in line 16 in apex.py, the gfortran compiler should live in a static location (/opt/local/bin). I have not figured out what @rpath refer to in the error above, but it may be the same location. I have tried to make symbolic links and copying the above located file to this location, with no luck. There is likely a simple solution to this, but I have unfortunately not been able to dig much deeper into this material. Any help here would be very much appreciated! I have no reason for claiming this to be a bug in Apexpy at this point. Thanks, -Jone — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or unsubscribe .
jpreistad commented 3 years ago

Thanks for the prompt response! I tried

pip uninstall apexpy
pip install --no-binary :apexpy: apexpy

However, still same error.

jpreistad commented 3 years ago

However, the message in apex.py saying that the compiler is assumed to live in "/opt/local/bin' could be wrong or misleading. My colleague recently installed apexpy on her new mac without issues. She does not have the fortran compiler in the above path.

aburrell commented 3 years ago

the message in apex.py saying that the compiler is assumed to live in "/opt/local/bin' could be wrong or misleading

Yes, that statement only applies to wheels, which were not included in this release. This should be clarified by specifying to which releases the compiler location assumption is applicable.

jpreistad commented 3 years ago

So I decided to start out with a fresh Big Sur install. The only commands issued after the disk erase of the system is:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install gcc
cd Downloads
zsh ./Anaconda3-2020.11-MacOSX-x86_64.sh

Then, installing Apexpy, and I get still a very similar error.

(base) jonw@c02f9621md6r ~ % pip install --no-binary :apexpy: apexpy

Collecting apexpy
  Downloading apexpy-1.1.0.tar.gz (5.9 MB)
     |████████████████████████████████| 5.9 MB 5.5 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy in ./anaconda3/lib/python3.8/site-packages (from apexpy) (1.19.2)
Building wheels for collected packages: apexpy
  Building wheel for apexpy (PEP 517) ... done
  Created wheel for apexpy: filename=apexpy-1.1.0-cp38-cp38-macosx_10_9_x86_64.whl size=281533 sha256=dccad450185402fe87589af78ecd81e87e3fb1016052d4ccc9d15a950ba06f5d
  Stored in directory: /Users/jonw/Library/Caches/pip/wheels/13/46/fc/d6ddeb015fb5ecc9916afea9f14d40b961117bf663ea757d93
Successfully built apexpy
Installing collected packages: apexpy
Successfully installed apexpy-1.1.0
(base) jonw@c02f9621md6r ~ % ipython
Python 3.8.5 (default, Sep  4 2020, 02:22:02) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import apexpy
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
/Users/jonw/anaconda3/lib/python3.8/site-packages/apexpy/apex.py:16: UserWarning: fortranapex module could not be imported, so apexpy probably won't work.  Make sure you have a gfortran compiler. Wheels installation assumes your compiler lives in /opt/local/bin
  warnings.warn("".join(["fortranapex module could not be imported, so ",
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-20ab8dd999be> in <module>
----> 1 import apexpy

~/anaconda3/lib/python3.8/site-packages/apexpy/__init__.py in <module>
      1 from __future__ import absolute_import, division, print_function
      2 
----> 3 from .apex import Apex, ApexHeightError
      4 from . import helpers
      5 

~/anaconda3/lib/python3.8/site-packages/apexpy/apex.py in <module>
     18                            "a gfortran compiler. Wheels installation ",
     19                            "assumes your compiler lives in /opt/local/bin"]))
---> 20     raise err
     21 
     22 # make sure invalid warnings are always shown

~/anaconda3/lib/python3.8/site-packages/apexpy/apex.py in <module>
     12 # Below try..catch required for autodoc to work on readthedocs
     13 try:
---> 14     from . import fortranapex as fa
     15 except ImportError as err:
     16     warnings.warn("".join(["fortranapex module could not be imported, so ",

ImportError: numpy.core.multiarray failed to import

From the Apexpy install using --no-binary option, it seems like wheels are used here. Does this mean that I am not using the same release of Apexpy as you were referring to @aburrell :

Yes, that statement only applies to wheels, which were not included in this release.

At the very bottom in the output above, python throw an import error on numpy.core.multiarray which is different from earlier. Not sure how this relate to apexpy. This import fine by itself.

aburrell commented 3 years ago

Ok! The problem is the numpy version (found this out last week). Something in 1.19.X broke and is fixed in 1.20.X. Can you upgrade numpy to the most current version?

jpreistad commented 3 years ago

Thank you so much for pointing this out, I really appreciate your help here! Now it works like a charm :)