[Thread Prev][Thread Next][Index]

Re: [ferret_users] Pyferret, jupyter notebook and ferretmagic



Hi Olivier,

Just to follow up on this.  I assume that using PyFerret built for your system (either through an Anaconda or a Homebrew build) has fixed the issues with finding the libraries from a previous discussion thread.

For PyFerret Python users using Jupyter notebooks:  

Jupyter notebooks started from JupyterHub do not normally have user's environment variables (such as those set in $HOME/.bashrc) for Python sessions.  If the PyFerret environment variables are not assigned in your Jupyter notebook, one can use the pyferret.addenv method with just the arguments FER_DIR= (path to pyferret installation directory) and FER_DAT= (path to datasets directory) to assign the default values.  There is also a pyferret.addpath method that adds to the environment variables just like the Faddpath command.  

However, the pyferret module needs to be found in order to use these pyferret methods.  If the pyferret module is not found when importing, then its location needs to be added to sys.path.  So something like the following, where ferdir is the (string) location of the PyFerret installation and ferdat is the (string) location of the datasets directory:
    import sys 
    sys.path.insert(1, '%s/lib/python%d.%d/site-packages' % (ferdir, sys.version_info[0], sys.version_info[1]))
    import pyferret
    pyferret.addenv(FER_DIR=ferdir, FER_DAT=ferdat)
    pyferret.start(journal=False, quiet=True, unmapped=True) 

Best regards,
Karl


On Mon, Aug 27, 2018 at 7:54 AM Olivier Marti <olivier.marti@xxxxxxxxxxxx> wrote:
Hello,

I have a functional PyFerret 7.4 on Mac OS X Sierra, with python 3.7 from HomeBrew. I'm now trying to use jupyter notebook and the ferretmagic module from Patrick (https://github.com/PBrockmann/ipython_ferretmagic)

What I get is : 

import pyferret
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-12-1563948a3fc8> in <module>()
----> 1 import pyferret

~/local/softs/PyFerret7.4_python3.7/lib/python3.7/site-packages/pyferret/__init__.py in <module>()
     43 import readline
     44 
---> 45 from pyferret import libpyferret
     46 # also import everything (not starting with an underscore) from libpyferret
     47 # so constants in that module are seen as part of this module

ImportError: dlopen(/Users/marti/local/softs/PyFerret7.4_python3.7/lib/python3.7/site-packages/pyferret/libpyferret.cpython-37m-darwin.so, 2): Library not loaded: /Users/ksmith/.local/opt/gcc/lib/gcc/8/libgfortran.5.dylib
  Referenced from: /Users/marti/local/softs/PyFerret7.4_python3.7/lib/python3.7/site-packages/pyferret/libpyferret.cpython-37m-darwin.so
  Reason: image not found


It means that python does not find libgfortran.5.dylib in any known path, and tries to load the default /Users/ksmith/.local/opt/gcc/lib/gcc/8/libgfortran.5.dylib hardwired in the pyferret library.

When launching pyferret from the shell, you have to set the environment variable DYLD_FALLBACK_LIBRARY_PATH to make pyferret available to find libgfortran.5.dylib.
I can't find a way to do that in a jupyter notebook :

Environment variables from the shell (PYTHONPATHDYLD_FALLBACK_LIBRARY_PATH) are not recognized by jupyter

Setting PYTHONPATH in the notebook allows to find the pyferret module, libpyferret.so and libpyferret.cpython-37m-darwin.soBut I can't find a way to force pyferret to find /Users/marti/local/softs/PyFerret7.4_python3.7/dylibs/libgfortran.5.dylib

No success when adding : os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = '/Users/marti/local/softs/PyFerret7.4_python3.7/dylibs'
      
 Any idea ??

Olivier 

-- 
Dr. Olivier Marti  - mailto:olivier.marti@xxxxxxxxxxxx
Laboratoire des Sciences du Climat et de l'Environnement
Institut Pierre Simon Laplace
Laboratoire CEA-CNRS-UVSQ  -  UMR 8212
Tel : +33 1 69 08 77 27 - Mob : +33 6 45 36 43 74
Fax : +33 1 69 08 30 73





--
Karl M. Smith, Ph.D.
JISAO Univ. Wash. and PMEL NOAA
"The contents of this message are mine personally and do
not necessarily reflect any position of the Government
or the National Oceanic and Atmospheric Administration."

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement