Import error in fresh FEniCSx conda-forge installation

Hi,
I have just installed FEniCSx and I’m trying to use it in Jupyter Lab. I followed these steps in MacOS Monterrey 12.4:

conda create -n fenicsx fenics-dolfinx mpich pyvista
conda activate fenicsx
conda install jupyterlab
python -m ipykernel install --user --name fenicsx --display-name "Python (FEniCSx)"

I didn’t have any problems during installation. However, when I open a notebook in Jupyter Lab I can’t event import numpy:

import numpy as np

produces the error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File ~/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/__init__.py:23, in <module>
     22 try:
---> 23     from . import multiarray
     24 except ImportError as exc:

File ~/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/multiarray.py:10, in <module>
      9 import functools
---> 10 from . import overrides
     11 from . import _multiarray_umath

File ~/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/overrides.py:6, in <module>
      4 import os
----> 6 from numpy.core._multiarray_umath import (
      7     add_docstring, implement_array_function, _get_implementing_args)
      8 from numpy.compat._inspect import getargspec

ImportError: dlopen(/Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): Library not loaded: @rpath/libopenblas.dylib
  Referenced from: /Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so
  Reason: tried: '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/../../../../libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/../../../../libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/bin/../lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/bin/../lib/libopenblas.dylib' (no such file), '/usr/local/lib/libopenblas.dylib' (no such file), '/usr/lib/libopenblas.dylib' (no such file)

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import numpy as np

File ~/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/__init__.py:144, in <module>
    141 # Allow distributors to run custom init code
    142 from . import _distributor_init
--> 144 from . import core
    145 from .core import *
    146 from . import compat

File ~/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/__init__.py:49, in <module>
     25     import sys
     26     msg = """
     27 
     28 IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
   (...)
     47 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     48         __version__, exc)
---> 49     raise ImportError(msg)
     50 finally:
     51     for envkey in env_added:

ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "/Users/myuser/opt/anaconda3/envs/fenicsx/bin/python"
  * The NumPy version is: "1.22.3"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): Library not loaded: @rpath/libopenblas.dylib
  Referenced from: /Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so
  Reason: tried: '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/../../../../libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/lib/python3.10/site-packages/numpy/core/../../../../libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/bin/../lib/libopenblas.dylib' (no such file), '/Users/myuser/opt/anaconda3/envs/fenicsx/bin/../lib/libopenblas.dylib' (no such file), '/usr/local/lib/libopenblas.dylib' (no such file), '/usr/lib/libopenblas.dylib' (no such file)

I tried conda install libopenblas, but the library is already there. Any ideas on how to solve this issue?

Dear @pamgur,

Thank you for your post. As of March 2024 I am experiencing the same problem.

Did you by any chance manage to resolve the issue?

Regards,

Gerald

Hi Gerald,
No, unfortunately I didn’t. I ended up using FEniCSx through Docker.

Dear @pamgur ,

Thank you for the email.

I successfully installed FEniCSx from scratch this year, 2024. I documented the procedure I followed just in case you may be interested.

Regards,

Gerald.

Sure, that would be awesome! Could you share a link?