ImportError on calling dolfinx.fem.form

I’m trying to solve a complex eigenvalue problem. I’ve installed anaconda using homebrew, and created an environment with conda create -n fenicsx-cmplx-env -c conda-forge fenics-dolfinx "petsc==complex" "petsc4py==complex mpich pyvista. The platform is macOS 26.5.2.

The ImportError manifests when I get to the stage of translating a UFL form to discrete FE, Here is a MWE:

#  2.5D wave propagation on rectangular bar, hacked from example in fenicsx primer

#  Problem parameters
Lx = 0.8
Ly = 0.6
rho = 1.0
mu = 1.0;
lam = 2.0;
k = 1.0;

from mpi4py import MPI
from dolfinx import mesh
import numpy as np

#  Mesh size
nx = 40
ny = 30

domain = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([0,0]), np.array([Lx,Ly])], [nx,ny], mesh.CellType.quadrilateral)

from dolfinx import fem
from dolfinx.fem import petsc
from basix.ufl import element, mixed_element

V = fem.functionspace(domain, ("Lagrange", 2))
from ufl import (
    TestFunctions,
    TrialFunctions,
    conj,
    div,
    dx,
    grad,
    inner,
    transpose,
)

# 1. Elements and Function Spaces
# In-plane component (2D vector element) and out-of-plane component (scalar element)
vector_el = element("Lagrange", domain.basix_cell(), 2, shape=(2,))
scalar_el = element("Lagrange", domain.basix_cell(), 2)
mixed_el = mixed_element([vector_el, scalar_el])

V = fem.functionspace(domain, mixed_el)

# Trial functions (u12, u3) and Test functions (v12, v3)
u12, u3 = TrialFunctions(V)
v12, v3 = TestFunctions(V)

# 3. Weak Form Construction (using integration by parts)
# Note: inner(a, b) automatically handles complex conjugate for b in UFL complex mode.

# --- Equation 1: In-plane components (u12) ---
# Weak form terms after integrating (grad(div(u12)) + div(grad(u12))) by parts:
a_in_plane = (
    lam * (div(u12) - 1j*k*u3) * div(conj(v12)) * dx
    + mu * inner(grad(u12)+transpose(grad(u12)), grad(v12)) * dx
    + mu * 1j * k * inner((grad(u3) - 1j*k*u12), v12) * dx
)
m_in_plane = rho * inner(u12, v12) * dx

# --- Equation 2: Out-of-plane component (u3) ---
# Weak form terms after integrating div(grad(u3)) by parts:
a_out_plane = (
    mu * inner((grad(u3) - 1j*k*u12), grad(v3)) * dx
    + lam * 1j * k * (div(u12) - 1j*k*u3) * conj(v3) * dx
    + 2 * mu * (k**2) * u3 * conj(v3) * dx
)
m_out_plane = rho * u3 * conj(v3) * dx

# Total Bilinear Form and mass matrix
a = a_in_plane + a_out_plane
m = m_in_plane + m_out_plane

# Assemble forms into PETSc Matrices: A * x = omega^2 * M * x
a_form = fem.form(a,dtype=np.complex128)

I’m aware of previous threads involving ImportErrors and libffcx* files in the fenics cache, but I believe my installation is more recent than the ones causing those problems. Here is the error trace:

---------------------------------------------------------------------------

ImportError                               Traceback (most recent call last)

Cell In[6], line 2
      1 # Assemble forms into PETSc Matrices: A * x = omega^2 * M * x
----> 2 a_form = fem.form(a,dtype=np.complex128)


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/fem/forms.py:337, in form(form, dtype, form_compiler_options, jit_options, entity_maps)
    334     else:
    335         return form
--> 337 return _create_form(form)


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/fem/forms.py:331, in form.<locals>._create_form(form)
    329         return None
    330     else:
--> 331         return _form(form)
    332 elif isinstance(form, collections.abc.Iterable):
    333     return list(map(lambda sub_form: _create_form(sub_form), form))


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/fem/forms.py:254, in form.<locals>._form(form)
    252 if mesh is None:
    253     raise RuntimeError("Expecting to find a Mesh in the form.")
--> 254 ufcx_form, module, code = jit.ffcx_jit(
    255     mesh.comm, form, form_compiler_options=form_compiler_options, jit_options=jit_options
    256 )
    258 # For each argument in form extract its function space
    259 V = [arg.ufl_function_space()._cpp_object for arg in form.arguments()]


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/jit.py:62, in mpi_jit_decorator.<locals>.mpi_jit(comm, *args, **kwargs)
     58 @functools.wraps(local_jit)
     59 def mpi_jit(comm, *args, **kwargs):
     60     # Just call JIT compiler when running in serial
     61     if comm.size == 1:
---> 62         return local_jit(*args, **kwargs)
     64     # Default status (0 == ok, 1 == fail)
     65     status = 0


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/jit.py:212, in ffcx_jit(ufl_object, form_compiler_options, jit_options)
    210 # Switch on type and compile, returning cffi object
    211 if isinstance(ufl_object, ufl.Form):
--> 212     r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
    213 elif isinstance(ufl_object, ufl.Mesh):
    214     r = ffcx.codegeneration.jit.compile_coordinate_maps([ufl_object], options=p_ffcx, **p_jit)


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/ffcx/codegeneration/jit.py:227, in compile_forms(forms, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
    224         pass
    225     raise e
--> 227 obj, module = _load_objects(cache_dir, module_name, form_names)
    228 return obj, module, (decl, impl)


File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/ffcx/codegeneration/jit.py:416, in _load_objects(cache_dir, module_name, object_names)
    413     raise ModuleNotFoundError("Unable to find JIT module.")
    415 # Load module
--> 416 compiled_module = importlib.util.module_from_spec(spec)
    417 spec.loader.exec_module(compiled_module)
    419 compiled_objects = []


File <frozen importlib._bootstrap>:813, in module_from_spec(spec)


File <frozen importlib._bootstrap_external>:1293, in ExtensionFileLoader.create_module(self, spec)
   1291 'Could not get source, probably due dynamically evaluated source code.'


File <frozen importlib._bootstrap>:488, in _call_with_frames_removed(f, *args, **kwds)


ImportError: dlopen(/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so, 0x0002): tried: '/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so' (duplicate LC_RPATH '/opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib'), '/System/Volumes/Preboot/Cryptexes/OS/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so' (no such file), '/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so' (duplicate LC_RPATH '/opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib')

I can’t reproduce the error on my system (user the docker images: ghcr.io/fenics/dolfinx/dolfinx:nightly and ghcr.io/fenics/dolfinx/dolfinx:stable).

To me it seems like you have installed dolfinx with conda.
Can you report the output of conda env export, as I get a working code with the following:

conda create -n test_dolfinx python=3.12 
conda activate test_dolfinx
conda install -c conda-forge fenics-dolfinx "petsc=*=complex*" mpich

My conda env export:

(test_dolfinx) dokken@Jorgens-MacBook-Pro debug_issues % conda env export
name: test_dolfinx
channels:
  - conda-forge
dependencies:
  - _openmp_mutex=4.5=7_kmp_llvm
  - _python_abi3_support=1.0=hd8ed1ab_3
  - bzip2=1.0.8=hd037594_9
  - c-ares=1.34.8=h84a0fba_0
  - c-blosc2=3.2.3=hf9886e1_0
  - ca-certificates=2026.7.22=hbd8a1cb_0
  - cctools=1030.6.3=llvm22_1_hbe26303_5
  - cctools_impl_osx-arm64=1030.6.3=llvm22_1_h7bf7afb_5
  - cffi=2.1.1=py312h652e2b1_0
  - clang=22.1.8=default_cfg_h4d70ba2_3
  - clang-22=22.1.8=default_h3bfd001_3
  - clang_impl_osx-arm64=22.1.8=default_hd222103_3
  - compiler-rt=22.1.8=hce30654_1
  - compiler-rt22=22.1.8=hd34ed20_1
  - compiler-rt22_osx-arm64=22.1.8=h7e67a1e_1
  - compiler-rt_osx-arm64=22.1.8=hce30654_1
  - cpython=3.12.13=py312hd8ed1ab_0
  - fenics-basix=0.11.0=py312h660ef66_0
  - fenics-basix-nanobind-abi=2.19=py312h7444122_0
  - fenics-dolfinx=0.11.0=py312h17da157_1
  - fenics-ffcx=0.11.0=pyh4a40500_0
  - fenics-libbasix=0.11.0=py312h9c3de7e_0
  - fenics-libdolfinx=0.11.0=py312h5661c18_1
  - fenics-ufcx=0.11.0=haec879b_0
  - fenics-ufl=2026.1.0=pyhc364b38_0
  - fftw=3.3.11=mpi_mpich_ha80cdc1_0
  - fmt=12.1.0=h403dcb5_0
  - hdf5=1.14.6=mpi_mpich_h15328f7_10
  - icu=78.3=hc7cc350_2
  - kahip=3.25=py313h49dea3b_0
  - krb5=1.22.2=hfd3d5f3_1
  - ld64=956.6=llvm22_1_h5b97f1b_5
  - ld64_osx-arm64=956.6=llvm22_1_h692d5aa_5
  - libadios2=2.12.1=mpi_mpich_h9117939_7
  - libaec=1.1.5=h8664d51_0
  - libamd=3.3.3=h5087772_7100102
  - libblas=3.11.0=8_h51639a9_openblas
  - libboost=1.90.0=h0419b56_1
  - libboost-devel=1.90.0=hf450f58_1
  - libboost-headers=1.90.0=hce30654_1
  - libbtf=2.3.2=h99b4a89_7100102
  - libcamd=3.3.3=h99b4a89_7100102
  - libcblas=3.11.0=8_hb0561ab_openblas
  - libccolamd=3.3.4=h99b4a89_7100102
  - libcholmod=5.3.1=hbba04d7_7100102
  - libclang-cpp22.1=22.1.8=default_hdca5a3d_3
  - libcolamd=3.3.4=h99b4a89_7100102
  - libcompiler-rt=22.1.8=hd34ed20_1
  - libcurl=8.21.0=hf618e03_4
  - libcxx=22.1.8=h55c6f16_0
  - libedit=3.1.20250104=pl5321hafb1f1b_0
  - libev=4.33=h93a5062_2
  - libexpat=2.8.1=hf6b4638_1
  - libfabric=2.6.0=hce30654_0
  - libfabric1=2.6.0=h84a0fba_0
  - libffi=3.5.2=hcf2aa1b_0
  - libgcc=16.1.0=h3cf6597_1
  - libgfortran=16.1.0=h07b0088_1
  - libgfortran5=16.1.0=h32cdfcc_1
  - libglib=2.88.3=ha08bb59_0
  - libhwloc=2.13.0=default_ha97f43a_1000
  - libiconv=1.18=h23cfdf5_2
  - libintl=0.25.1=h493aca8_0
  - libklu=2.3.5=h4370aa4_7100102
  - liblapack=3.11.0=8_hd9741b5_openblas
  - libllvm22=22.1.8=h89af1be_1
  - liblzma=5.8.3=h8088a28_0
  - libnghttp2=1.68.1=h8f3e76b_0
  - libopenblas=0.3.33=openmp_he657e61_0
  - libpng=1.6.58=h132b30e_0
  - libpsl=0.23.0=h7a62e17_0
  - libptscotch=7.0.11=int32_h5b861dd_3
  - libscotch=7.0.11=int32_ha9e4f68_3
  - libsigtool=0.1.3=h98dc951_0
  - libsodium=1.0.22=h1a92334_1
  - libspqr=4.3.4=h775d698_7100102
  - libsqlite=3.53.4=h1ae2325_0
  - libssh2=1.11.1=h1590b86_0
  - libsuitesparseconfig=7.10.1=h4a8fc20_7100102
  - libumfpack=6.3.5=h7c2c975_7100102
  - libxml2=2.15.3=h5654f7c_0
  - libxml2-16=2.15.3=h5ef1a60_0
  - libzlib=1.3.2=h8088a28_3
  - llvm-openmp=22.1.8=hc7d1edf_0
  - llvm-tools=22.1.8=hd34ed20_1
  - llvm-tools-22=22.1.8=hb545844_1
  - lz4-c=1.10.0=h286801f_1
  - metis=5.1.0=h15f6cfe_1007
  - mpi=1.0.1=mpich
  - mpi4py=4.1.2=py312he177456_100
  - mpich=5.0.1=ha380261_2
  - mumps-include=5.8.2=ha6078a4_2
  - mumps-mpi=5.8.2=h6d3bd2c_2
  - nanobind-abi=19=hd8ed1ab_0
  - ncurses=6.6=h1d4f5a5_0
  - numpy=2.5.1=py312ha003a3f_0
  - openssl=3.6.3=hd24854e_0
  - packaging=26.2=pyhc364b38_0
  - parmetis=4.0.3=h0472811_1009
  - pcre2=10.47=h30297fc_0
  - petsc=3.25.4=complex_h8e5b740_0
  - petsc4py=3.25.4=np2py310h2ddef32_0
  - pip=26.2=pyh8b19718_0
  - pkg-config=0.29.2=hde07d2e_1009
  - pugixml=1.15=hd3d436d_0
  - pycparser=3.0=pyhcf101f3_0
  - python=3.12.13=h8561d8f_0_cpython
  - python-gil=3.12.13=hd8ed1ab_0
  - python_abi=3.12=8_cp312
  - readline=8.3=h46df422_0
  - scalapack=2.2.0=hf586d3d_6
  - setuptools=83.0.0=pyh332efcf_0
  - sigtool-codesign=0.1.3=h98dc951_0
  - slepc=3.25.1=complex_hb06dc49_0
  - slepc4py=3.25.1=np2py310h5a3b464_0
  - spdlog=1.17.0=ha0f8610_1
  - superlu=7.0.0=h742a510_1
  - superlu_dist=9.2.1=h339bd1a_2
  - tapi=1600.0.11.8=h997e182_2
  - tk=8.6.13=hd3d0363_3
  - tzdata=2026c=h151e31d_0
  - wheel=0.47.0=pyhd8ed1ab_0
  - yaml=0.2.5=h925e9cb_3
  - zeromq=4.3.5=h10816f8_11
  - zfp=1.0.1=ha86207d_5
  - zlib-ng=2.3.3=hed4e4f5_1
  - zstd=1.5.7=hbf9d68e_6
prefix: /Users/dokken/Documents/src/miniforge3/envs/test_dolfinx

Could you try clearing your cache, i.e. call rm -rf /Users/wrg11/.cache/fenics

Thanks for looking at this …

Yes, I installed with conda. The specific commands I used are given in the first paragraph of my original post. I get an error whether or not I clear the cache before running, but the traceback I included is from after clearing.

The output from conda env export follows

name: fenicsx-cmplx-env
channels:

  • conda-forge
    dependencies:
  • _openmp_mutex=4.5=7_kmp_llvm
  • _python_abi3_support=1.0=hd8ed1ab_3
  • aiohappyeyeballs=2.7.1=pyhd8ed1ab_0
  • aiohttp=3.14.3=py312h9f8c436_0
  • aiosignal=1.4.0=pyhd8ed1ab_0
  • anyio=4.14.2=pyhcf101f3_0
  • appnope=0.1.4=pyhd8ed1ab_1
  • argon2-cffi=25.1.0=pyhd8ed1ab_0
  • argon2-cffi-bindings=25.1.0=py312h4409184_2
  • arrow=1.4.0=pyhcf101f3_0
  • asttokens=3.0.2=pyhd8ed1ab_0
  • async-lru=2.3.0=pyhcf101f3_0
  • attrs=26.1.0=pyhcf101f3_0
  • babel=2.18.0=pyhcf101f3_1
  • backports.zstd=1.6.0=py312h87c4bb7_0
  • beautifulsoup4=4.15.0=pyha770c72_0
  • bleach=6.4.0=pyhcf101f3_0
  • bleach-with-css=6.4.0=hac0b51c_0
  • blosc=1.21.6=h7dd00d9_1
  • brotli=1.2.0=h7d5ae5b_1
  • brotli-bin=1.2.0=hc919400_1
  • brotli-python=1.2.0=py312h0dfefe5_1
  • bzip2=1.0.8=hd037594_9
  • c-ares=1.34.8=h84a0fba_0
  • c-blosc2=2.15.2=h9cbb436_1
  • ca-certificates=2026.7.22=hbd8a1cb_0
  • cached-property=1.5.2=hd8ed1ab_2
  • cached_property=1.5.2=pyha770c72_2
  • cairo=1.18.4=h6a3b0d2_0
  • cctools_osx-arm64=1010.6=h318dc9b_3
  • certifi=2026.7.22=pyhd8ed1ab_0
  • cffi=1.16.0=py312h8e38eb3_0
  • charset-normalizer=3.4.9=pyhd8ed1ab_0
  • clang=17.0.6=default_h474c9e2_8
  • clang-17=17.0.6=default_hf90f093_8
  • clang_impl_osx-arm64=17.0.6=he47c785_23
  • clang_osx-arm64=17.0.6=h07b0088_23
  • clangxx=17.0.6=default_h1ffe849_8
  • comm=0.2.3=pyhe01879c_0
  • compiler-rt=17.0.6=h856b3c1_2
  • compiler-rt_osx-arm64=17.0.6=h832e737_2
  • contourpy=1.3.3=py312h3093aea_4
  • cpython=3.12.13=py312hd8ed1ab_0
  • cycler=0.12.1=pyhcf101f3_2
  • cyclopts=4.22.2=pyhcf101f3_0
  • cyrus-sasl=2.1.28=ha1cbb27_0
  • debugpy=1.8.21=py312h6510ced_0
  • defusedxml=0.7.1=pyhd8ed1ab_0
  • docstring_parser=0.18.0=pyhd8ed1ab_0
  • double-conversion=3.3.1=h286801f_0
  • exceptiongroup=1.3.1=pyhd8ed1ab_0
  • executing=2.2.1=pyhd8ed1ab_0
  • fenics-basix=0.9.0=py312hb6f5eea_1
  • fenics-basix-nanobind-abi=0.2.1.17=h081cc67_1
  • fenics-dolfinx=0.9.0=py312h4ec2853_2
  • fenics-ffcx=0.9.0=pyh2e48890_0
  • fenics-libbasix=0.9.0=h12e1e3e_1
  • fenics-libdolfinx=0.9.0=hf384842_2
  • fenics-ufcx=0.9.0=hb7f7608_0
  • fenics-ufl=2024.2.0=pyhd8ed1ab_1
  • fftw=3.3.10=mpi_mpich_h6eb47b5_11
  • fmt=10.2.1=h2ffa867_0
  • font-ttf-dejavu-sans-mono=2.37=hab24e00_0
  • font-ttf-inconsolata=3.000=h77eed37_0
  • font-ttf-source-code-pro=2.038=h77eed37_0
  • font-ttf-ubuntu=0.83=h77eed37_3
  • fontconfig=2.18.2=h2b252f5_0
  • fonts-conda-ecosystem=1=0
  • fonts-conda-forge=1=hc364b38_1
  • fonttools=4.63.0=py312h04c11ed_0
  • fqdn=1.5.1=pyhd8ed1ab_1
  • freetype=2.14.3=hce30654_1
  • frozenlist=1.8.0=py312ha0ce254_0
  • gl2ps=1.4.2=h8fb3f6e_2
  • glew=2.1.0=h9f76cd9_2
  • gmp=6.3.0=h7bae524_2
  • graphite2=1.3.15=hf6b4638_0
  • h11=0.16.0=pyhcf101f3_1
  • h2=4.4.0=pyhcf101f3_0
  • harfbuzz=11.1.0=hab40de2_0
  • hdf4=4.2.15=h2ee6834_7
  • hdf5=1.14.3=mpi_mpich_h13a04de_9
  • hpack=4.2.0=pyhd8ed1ab_0
  • httpcore=1.0.9=pyh29332c3_0
  • httpx=0.28.1=pyhd8ed1ab_0
  • hyperframe=6.1.0=pyhd8ed1ab_0
  • hypre=2.31.0=mpi_mpich_hbb1104e_1
  • icu=75.1=hfee45f7_0
  • idna=3.18=pyhcf101f3_0
  • importlib-metadata=9.0.0=pyhcf101f3_0
  • ipykernel=7.3.0=pyh01cf8df_0
  • ipython=9.16.0=pyh53cf698_0
  • ipython_pygments_lexers=1.1.1=pyhd8ed1ab_0
  • isoduration=20.11.0=pyhd8ed1ab_1
  • jedi=0.20.0=pyhcf101f3_0
  • jinja2=3.1.6=pyhcf101f3_1
  • json5=0.15.0=pyhd8ed1ab_0
  • jsoncpp=1.9.6=h726d253_1
  • jsonpointer=3.1.1=pyhcf101f3_0
  • jsonschema=4.26.0=pyhcf101f3_0
  • jsonschema-specifications=2025.9.1=pyhcf101f3_0
  • jsonschema-with-format-nongpl=4.26.0=hcf101f3_0
  • jupyter-builder=1.2.1=pyhcf101f3_0
  • jupyter-lsp=2.3.1=pyhcf101f3_0
  • jupyter_client=8.9.1=pyhcf101f3_0
  • jupyter_core=5.9.1=pyhc90fa1f_0
  • jupyter_events=0.12.1=pyhcf101f3_0
  • jupyter_server=2.20.0=pyhcf101f3_0
  • jupyter_server_terminals=0.5.4=pyhcf101f3_0
  • jupyterlab=4.6.2=pyhd8ed1ab_0
  • jupyterlab_pygments=0.3.0=pyhd8ed1ab_2
  • jupyterlab_server=2.28.0=pyhcf101f3_0
  • kahip=3.16=py312h24aff45_4
  • kiwisolver=1.5.0=py312h3093aea_0
  • krb5=1.21.3=h237132a_0
  • lark=1.3.1=pyhd8ed1ab_0
  • lcms2=2.19.1=hdfa7624_1
  • ld64_osx-arm64=951.9=h58ff2e4_3
  • lerc=4.2.0=h1eee2c3_0
  • libadios2=2.10.1=mpi_mpich_h425ff31_4
  • libaec=1.1.5=h8664d51_0
  • libblas=3.11.0=8_h51639a9_openblas
  • libboost=1.86.0=hf493ff8_4
  • libboost-devel=1.86.0=hf450f58_4
  • libboost-headers=1.86.0=hce30654_4
  • libbrotlicommon=1.2.0=hc919400_1
  • libbrotlidec=1.2.0=hc919400_1
  • libbrotlienc=1.2.0=hc919400_1
  • libcblas=3.11.0=8_hb0561ab_openblas
  • libclang-cpp17=17.0.6=default_hf90f093_8
  • libclang-cpp18.1=18.1.8=default_hf3020a7_18
  • libclang13=21.1.0=default_h6e8f826_1
  • libcurl=8.18.0=he38603e_0
  • libcxx=22.1.8=h55c6f16_0
  • libcxx-devel=17.0.6=h86353a2_6
  • libdeflate=1.25=hc11a715_0
  • libedit=3.1.20250104=pl5321hafb1f1b_0
  • libev=4.33=h93a5062_2
  • libexpat=2.8.1=hf6b4638_1
  • libfabric=2.6.0=hce30654_0
  • libfabric1=2.6.0=h84a0fba_0
  • libffi=3.5.2=hcf2aa1b_0
  • libfreetype=2.14.3=hce30654_1
  • libfreetype6=2.14.3=hdfa99f5_1
  • libgcc=16.1.0=h3cf6597_1
  • libgfortran=16.1.0=h07b0088_1
  • libgfortran5=16.1.0=h32cdfcc_1
  • libglib=2.84.0=hdff4504_0
  • libhwloc=2.12.1=default_h88f92a7_1000
  • libiconv=1.18=h23cfdf5_2
  • libintl=0.25.1=h493aca8_0
  • libjpeg-turbo=3.2.0=h84a0fba_0
  • liblapack=3.11.0=8_hd9741b5_openblas
  • libllvm17=17.0.6=hc4b4ae8_3
  • libllvm18=18.1.8=default_h3f49643_9
  • libllvm21=21.1.0=h846d351_0
  • liblzma=5.8.3=h8088a28_0
  • libnetcdf=4.9.2=nompi_h610d594_116
  • libnghttp2=1.68.1=h8f3e76b_0
  • libntlm=1.8=h5505292_0
  • libogg=1.3.5=h48c0fde_1
  • libopenblas=0.3.33=openmp_he657e61_0
  • libpng=1.6.58=h132b30e_0
  • libpq=17.7=h944245b_1
  • libptscotch=7.0.5=ha7c25b6_4
  • libscotch=7.0.5=hc2b2845_4
  • libsigtool=0.1.3=h98dc951_0
  • libsodium=1.0.20=h99b78c6_0
  • libsqlite=3.53.4=h1b79a29_0
  • libssh2=1.11.1=h1590b86_0
  • libtheora=1.1.1=h99b78c6_1006
  • libtiff=4.7.2=h282da08_0
  • libvorbis=1.3.7=h81086ad_2
  • libwebp-base=1.6.0=h07db88b_0
  • libxcb=1.17.0=hdb1d25a_0
  • libxml2=2.13.9=h4a9ca0c_0
  • libzip=1.11.2=h1336266_0
  • libzlib=1.3.2=h8088a28_3
  • llvm-openmp=22.1.8=hc7d1edf_0
  • llvm-tools=17.0.6=hc4b4ae8_3
  • loguru=0.7.3=pyh707e725_0
  • lz4-c=1.10.0=h286801f_1
  • markdown-it-py=4.2.0=pyhd8ed1ab_0
  • markupsafe=3.0.3=py312h04c11ed_1
  • matplotlib-base=3.10.9=py312hf3defc7_0
  • matplotlib-inline=0.2.2=pyhd8ed1ab_0
  • mdurl=0.1.2=pyhd8ed1ab_1
  • metis=5.1.0=h15f6cfe_1007
  • mistune=3.3.4=pyhcf101f3_0
  • mpfr=4.2.2=h6bc93b0_0
  • mpi=1.0.1=mpich
  • mpi4py=4.1.2=py312he177456_100
  • mpich=4.3.2=hf5485c1_101
  • msgpack-python=1.2.1=py312h3093aea_1
  • multidict=6.7.1=py312h43af8aa_0
  • mumps-include=5.7.3=hce30654_5
  • mumps-mpi=5.7.3=h83d4000_5
  • munkres=1.1.4=pyhd8ed1ab_1
  • mysql-common=9.2.0=hd7719f6_0
  • mysql-libs=9.2.0=ha8be5b7_0
  • nbclient=0.11.0=pyhd8ed1ab_0
  • nbconvert-core=7.17.1=pyhcf101f3_0
  • nbformat=5.10.4=pyhd8ed1ab_1
  • ncurses=6.6=h1d4f5a5_0
  • nest-asyncio2=1.7.2=pyhcf101f3_0
  • nlohmann_json=3.12.0=h784d473_1
  • notebook=7.6.1=pyhcf101f3_0
  • notebook-shim=0.2.4=pyhd8ed1ab_1
  • numpy=1.26.4=py312h8442bc7_0
  • openjpeg=2.5.4=hd9e9057_0
  • openldap=2.6.10=hbe55e7a_0
  • openssl=3.6.3=hd24854e_0
  • overrides=7.7.0=pyhd8ed1ab_1
  • packaging=26.2=pyhc364b38_0
  • pandocfilters=1.5.0=pyhd8ed1ab_0
  • parmetis=4.0.3=hdd7d3b5_1008
  • parso=0.8.7=pyhcf101f3_0
  • pcre2=10.44=ha881caa_2
  • petsc=3.21.6=complex_h2a9a271_0
  • petsc4py=3.21.1=complex_h213842d_0
  • pexpect=4.9.0=pyhd8ed1ab_1
  • pillow=12.0.0=py312h261a3e5_1
  • pip=26.2=pyh8b19718_0
  • pixman=0.46.4=h784d473_2
  • pkg-config=0.29.2=hde07d2e_1009
  • platformdirs=4.11.0=pyhcf101f3_0
  • pooch=1.9.0=pyhd8ed1ab_0
  • proj=9.5.1=h1318a7e_0
  • prometheus_client=0.26.0=pyhd8ed1ab_0
  • prompt-toolkit=3.0.53=pyha770c72_0
  • propcache=0.5.2=py312h04c11ed_0
  • psutil=7.2.2=py312hb3ab3e3_0
  • pthread-stubs=0.4=hd74edd7_1002
  • ptyprocess=0.7.0=pyhd8ed1ab_1
  • pugixml=1.14=h13dd4ca_0
  • pure_eval=0.2.3=pyhd8ed1ab_1
  • pycparser=3.0=pyhcf101f3_0
  • pygments=2.20.0=pyhd8ed1ab_0
  • pyobjc-core=12.2.1=py312h55b240b_0
  • pyobjc-framework-cocoa=12.2.1=py312h22cf174_0
  • pyparsing=3.3.2=pyhcf101f3_0
  • pysocks=1.7.1=pyha55dd90_7
  • python=3.12.13=h8561d8f_0_cpython
  • python-dateutil=2.9.0.post0=pyhe01879c_2
  • python-fastjsonschema=2.22.1=pyhcf101f3_0
  • python-gil=3.12.13=hd8ed1ab_0
  • python-json-logger=4.1.0=pyhd8ed1ab_0
  • python-tzdata=2026.3=pyhd8ed1ab_0
  • python_abi=3.12=8_cp312
  • pyvista=0.48.4=pyhd8ed1ab_1
  • pyyaml=6.0.3=py312h04c11ed_1
  • pyzmq=27.1.0=py312h022ad19_3
  • qhull=2020.2=h420ef59_5
  • qt6-main=6.8.3=hca13b62_2
  • readline=8.3=h46df422_0
  • referencing=0.37.0=pyhcf101f3_0
  • requests=2.34.2=pyhcf101f3_0
  • rfc3339-validator=0.1.4=pyhd8ed1ab_1
  • rfc3986-validator=0.1.1=pyh9f0ad1d_0
  • rfc3987-syntax=1.1.0=pyhe01879c_1
  • rich=15.0.0=pyhcf101f3_0
  • rich-rst=2.1.0=pyhd8ed1ab_0
  • rpds-py=2026.6.3=py312h8b1d842_0
  • scalapack=2.2.0=h1b9cfae_5
  • scooby=0.11.2=pyhd8ed1ab_0
  • send2trash=2.1.0=pyh5552912_1
  • setuptools=83.0.0=pyh332efcf_0
  • sigtool=0.1.3=h98dc951_0
  • sigtool-codesign=0.1.3=h98dc951_0
  • six=1.17.0=pyhe01879c_1
  • slepc=3.21.2=complex_h48a1f02_200
  • slepc4py=3.21.2=py312h56d8d15_0
  • snappy=1.2.2=hada39a4_1
  • sniffio=1.3.1=pyhd8ed1ab_2
  • soupsieve=2.9.1=pyhd8ed1ab_0
  • spdlog=1.13.0=h5fcca99_0
  • sqlite=3.53.4=h85ec8f2_0
  • stack_data=0.6.3=pyhd8ed1ab_1
  • suitesparse=7.8.2=hec630bf_0
  • superlu=7.0.0=h742a510_1
  • superlu_dist=9.1.0=h89afcdd_0
  • tapi=1300.6.5=h03f4b80_0
  • tbb=2022.3.0=h66ce52b_1
  • terminado=0.18.1=pyhc90fa1f_1
  • tinycss2=1.4.0=pyhd8ed1ab_0
  • tk=8.6.13=hd3d0363_3
  • tomli=2.4.1=pyhcf101f3_0
  • tornado=6.5.7=py312h2bbb03f_0
  • traitlets=5.16.0=pyhcf101f3_0
  • typing-extensions=4.16.0=h69aa097_0
  • typing_extensions=4.16.0=pyhcf101f3_0
  • typing_utils=0.1.0=pyhd8ed1ab_1
  • tzdata=2026c=h151e31d_0
  • unicodedata2=17.0.1=py312h2bbb03f_0
  • uri-template=1.3.0=pyhd8ed1ab_1
  • urllib3=2.7.0=pyhd8ed1ab_0
  • utfcpp=4.09=hce30654_0
  • vtk-base=9.3.1=qt_py312h269b868_215
  • wcwidth=0.8.2=pyhd8ed1ab_0
  • webcolors=25.10.0=pyhd8ed1ab_0
  • webencodings=0.5.1=pyhd8ed1ab_3
  • websocket-client=1.9.0=pyhd8ed1ab_0
  • wheel=0.47.0=pyhd8ed1ab_0
  • wslink=2.5.7=pyhd8ed1ab_0
  • xorg-libxau=1.0.12=hc919400_1
  • xorg-libxdmcp=1.1.5=hc919400_1
  • yaml=0.2.5=h925e9cb_3
  • yarl=1.24.5=py312h04c11ed_0
  • zeromq=4.3.5=h888dc83_9
  • zfp=0.5.5=hcfdfaf5_8
  • zipp=4.1.0=pyhcf101f3_0
  • zlib=1.3.2=h8088a28_3
  • zlib-ng=2.2.5=h3470cca_1
  • zstd=1.5.7=hbf9d68e_6
    prefix: /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env

I can reproduce your error with the env described above:

    a_form = fem.form(a,dtype=np.complex128)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/dolfinx/fem/forms.py", line 337, in form
    return _create_form(form)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/dolfinx/fem/forms.py", line 331, in _create_form
    return _form(form)
           ^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/dolfinx/fem/forms.py", line 254, in _form
    ufcx_form, module, code = jit.ffcx_jit(
                              ^^^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/dolfinx/jit.py", line 62, in mpi_jit
    return local_jit(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/dolfinx/jit.py", line 212, in ffcx_jit
    r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/ffcx/codegeneration/jit.py", line 227, in compile_forms
    obj, module = _load_objects(cache_dir, module_name, form_names)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib/python3.12/site-packages/ffcx/codegeneration/jit.py", line 416, in _load_objects
    compiled_module = importlib.util.module_from_spec(spec)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 813, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1293, in create_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
ImportError: dlopen(/Users/dokken/.cache/fenics/libffcx_forms_9db72cfabd343b850ce2e9baa0d544a55cbcd6fe.cpython-312-darwin.so, 0x0002): tried: '/Users/dokken/.cache/fenics/libffcx_forms_9db72cfabd343b850ce2e9baa0d544a55cbcd6fe.cpython-312-darwin.so' (duplicate LC_RPATH '/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib'), '/System/Volumes/Preboot/Cryptexes/OS/Users/dokken/.cache/fenics/libffcx_forms_9db72cfabd343b850ce2e9baa0d544a55cbcd6fe.cpython-312-darwin.so' (no such file), '/Users/dokken/.cache/fenics/libffcx_forms_9db72cfabd343b850ce2e9baa0d544a55cbcd6fe.cpython-312-darwin.so' (duplicate LC_RPATH '/Users/dokken/Documents/src/miniforge3/envs/my_new_env/lib')

I see that you are running an old version of FEniCS (0.9.0). Could you try to upgrade, i.e. make an environment with:

conda create -n test_dolfinx python=3.12 
conda activate test_dolfinx
conda install -c conda-forge fenics-dolfinx=0.11 "petsc=*=complex*" mpich

That worked - thanks! A couple of points for future reference:

  1. I also needed
    conda install -c conda-forge jupyterlab notebook
    conda install -c conda-forge pyvista

  2. My 0.9.0 installation was created following the instructions here:
    Download | FEniCS Project
    Maybe they could be revisited?

As the documentation recommends using v0.11, which should be the default one you get from conda these days, I’m not sure what you would like to modify in the instructions. Can you be more specific?

Yes; apologies for being opaque …

I didn’t have any previous versions installed, and I followed the instructions on the 0.11 download page that I linked. Specifically, I used

conda install -c conda-forge fenics-dolfinx mpich pyvista

to get FEniCS. This gave me the 0.9.0 version that you spotted, not the default 0.11 that’s expected.

That is rather weird, did you do this inside an existing conda environment (that might have had some dependencies that pinned fenics-dolfinx to 0.9) or did you do this is in a fresh environment?

Retraction (apologies); I didn’t use the standard command because I wanted a complex environment. Instead, the input was:

conda create -n fenicsx-cmplx-env -c conda-forge fenics-dolfinx “petsc==complex" "petsc4py==complex” mpich pyvista

conda activate fenicsx-cmplx-env

conda install -c conda-forge jupyterlab notebook

I don’t have a record of which environment I was in, but it will either have been base (most likely), or fenicsx-env (created following the download page instructions).

If I run:

 conda create -n fenicsx-cmplx-env -c conda-forge fenics-dolfinx "petsc=*=complex*" "petsc4py=*=complex*" mpich pyvista

i also get v0.9.0
I think the offending line is:
“petsc4py==complex”, because if you remove that line and run:

 conda create -n fenicsx-cmplx-env -c conda-forge fenics-dolfinx "petsc=*=complex*" mpich pyvista

you get v0.11 of FEniCS

Many thanks for following this up - impressive detective work!