Error importing dolfinx using conda: function() argument 'code' must be code, not str

Hello everyone

I’m new with FEniCS and I’m trying to get the latest release (FEniCSx 0.5) running in conda. So far, I have installed it in conda using the commands

conda create -n mecanica
conda activate mecanica
conda install -c conda-forge fenics-dolfinx mpich pyvista

After that, I have checked that the corresponding modules appear in my environment, but when I try to import dolfinx using

import dolfinx

I get the following error:

TypeError: function() argument 'code' must be code, not str

Any idea of how may I solve it?

Thank you!

In case it helps, the complete error is:

TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_45532/ in <module>
----> 1 import dolfinx

~/anaconda3/envs/mecanica/lib/python3.10/site-packages/dolfinx/ in <module>
     29 from dolfinx import common
     30 from dolfinx import cpp as _cpp
---> 31 from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot
     32 # Initialise logging
     33 from dolfinx.common import (TimingType, git_commit_hash, has_debug, has_kahip,

~/anaconda3/envs/mecanica/lib/python3.10/site-packages/dolfinx/fem/ in <module>
      9 from dolfinx.cpp.fem import IntegralType
     10 from dolfinx.cpp.fem import create_sparsity_pattern as _create_sparsity_pattern
---> 11 from dolfinx.fem import petsc
     12 from dolfinx.fem.assemble import (apply_lifting, assemble_matrix,
     13                                   assemble_scalar, assemble_vector, set_bc)

~/anaconda3/envs/mecanica/lib/python3.10/site-packages/dolfinx/fem/ in <module>
     22 from dolfinx.cpp.fem import pack_coefficients as _pack_coefficients
     23 from dolfinx.cpp.fem import pack_constants as _pack_constants
---> 24 from dolfinx.fem import assemble
     25 from dolfinx.fem.bcs import DirichletBCMetaClass
     26 from dolfinx.fem.bcs import bcs_by_block as _bcs_by_block

~/anaconda3/envs/mecanica/lib/python3.10/site-packages/dolfinx/fem/ in <module>
     20 from dolfinx.cpp.fem import pack_constants as _pack_constants
     21 from dolfinx.fem.bcs import DirichletBCMetaClass
---> 22 from dolfinx.fem.forms import FormMetaClass, form_types

~/anaconda3/envs/mecanica/lib/python3.10/site-packages/dolfinx/fem/ in <module>
     11 import typing
---> 13 from dolfinx.fem.function import FunctionSpace
     15 if typing.TYPE_CHECKING:

~/anaconda3/envs/mecanica/lib/python3.10/site-packages/dolfinx/fem/ in <module>
---> 30 class Constant(ufl.Constant):
     31     def __init__(self, domain, c: typing.Union[np.ndarray, typing.Sequence, float]):
     32         """A constant with respect to a domain.

TypeError: function() argument 'code' must be code, not str
1 Like

Possible duplicate of: Error importing dolfinx - #2 by cas91