# How to Run FEniCS with Spyder IDE in macOS Monterey?

Hi

I am new to FEniCS. Previously I have worked in MATLAB and that is why I wanted to run FEniCS with Spyder IDE. I followed the following thread and GitHub instructions (originally given for LINUX) and applied them to my platform

platform: M2 MacBook Pro, macOS Monterey version 12.6

After following all the steps, I ran the “demo_poisson.py” file on Spyder

> """
> demo_poisson.py file
>
> FEniCS tutorial demo program: Poisson equation with Dirichlet conditions.
> Test problem is chosen to give an exact solution at all nodes of the mesh.
>
>   -Laplace(u) = f    in the unit square
>             u = u_D  on the boundary
>
>   u_D = 1 + x^2 + 2y^2
>     f = -6
> """
>
> from __future__ import print_function
> # from fenics import *   # Triggers wildcard imports!!
> import fenics as fe
> import matplotlib.pyplot as plt
>
> # Create mesh and define function space
>
> # mesh = UnitSquareMesh(8, 8)
> # V = FunctionSpace(mesh, 'P', 1)
> mesh = fe.UnitSquareMesh(8,8)
> V = fe.FunctionSpace(mesh, 'P', 1)
>
> # Define boundary condition
> # u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
> u_D = fe.Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
>
> def boundary(x, on_boundary):
>     return on_boundary
>
> # bc = DirichletBC(V, u_D, boundary)
> bc = fe.DirichletBC(V, u_D, boundary)
>
> # Define variational problem
> # Similarly adding fe. to avoid wildcard imports
> u = fe.TrialFunction(V)
> v = fe.TestFunction(V)
> f = fe.Constant(-6.0)
> L = f*v*fe.dx
>
> # Compute solution
> u = fe.Function(V)
> fe.solve(a == L, u, bc)
>
> # Plot solution and mesh
> fe.plot(u)
> fe.plot(mesh)
>
> # Save solution to file in VTK format
> vtkfile = fe.File('poisson/solution.pvd')
> vtkfile << u
>
> # Compute error in L2 norm
> error_L2 = fe.errornorm(u_D, u, 'L2')
>
> # Compute maximum error at vertices
> vertex_values_u_D = u_D.compute_vertex_values(mesh)
> vertex_values_u = u.compute_vertex_values(mesh)
> import numpy as np
> error_max = np.max(np.abs(vertex_values_u_D - vertex_values_u))
>
> # Print errors
> print('error_L2  =', error_L2)
> print('error_max =', error_max)
>
> # Hold plot
> plt.show()

And got the following import error

>
> Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:06:49)
>
> IPython 8.4.0 -- An enhanced Interactive Python.
>
> runfile('/Users/jt/Documents/FEniCS/Ex1-Poisson/demo_poisson.py', wdir='/Users/jt/Documents/FEniCS/Ex1-Poisson')
> Traceback (most recent call last):
>
>   File ~/Documents/FEniCS/Ex1-Poisson/demo_poisson.py:14 in <module>
>     import fenics as fe
>
>   File ~/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/fenics/__init__.py:7 in <module>
>     from dolfin import *
>
>   File ~/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/__init__.py:34 in <module>
>     from .cpp import __version__
>
> ImportError: dlopen(/Users/jt/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/cpp.cpython-38-darwin.so, 0x0002): Library not loaded: '@rpath/libopenblas.dylib'
>   Referenced from: '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libumfpack.5.7.9.dylib'
>   Reason: tried: '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/../../../libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/../../../libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/bin/../lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/bin/../lib/libopenblas.dylib' (no such file), '/usr/local/lib/libopenblas.dylib' (no such file), '/usr/lib/libopenblas.dylib' (no such file)Library not loaded: '@rpath/libopenblas.dylib'
>   Referenced from: '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libcholmod.3.0.14.dylib'
>   Reason: tried: '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/../../../libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/../../../libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/bin/../lib/libopenblas.dylib' (no such file), '/Users/jt/opt/anaconda3/envs/fenicsproject/bin/../lib/libopenblas.dylib' (no such file), '/usr/local/lib/libopenblas.dylib' (no such file), '/usr/lib/libopenblas.dylib' (no such file)

PS: I tried the same installation on Ubuntu and it worked. However, it’s giving me the above import error in macOS Monterey