Fem.petsc not found in complex-mode

Dear FEniCS community.

I’m facing an AttributeError error when trying to run a code with complex-mode in Dolfinx v0.7.3 Docker image. The code below

import dolfinx
import ufl
import basix
from mpi4py import MPI


msh = dolfinx.mesh.create_interval(comm=MPI.COMM_WORLD,
                                   nx=10, points=[-1, 1])


Ph = basix.ufl.element("Lagrange", msh.basix_cell(), 1)

V = dolfinx.fem.functionspace(msh, Ph)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)

K = -ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx
Kform = dolfinx.fem.form(K)

dolfinx.fem.petsc.assemble_matrix(Kform, bcs=[])

is followed by the error

AttributeError: module 'dolfinx.fem' has no attribute 'petsc'

This code runs ok if we use real-mode. I cannot reproduce this on the dolfinx conda installation.

Thanks in advance!

You should explicitly import the petsc sub-module,
ie
import dolfinx.fem.petsc.
This is because petsc is not a mandatory requirement.

Im still getting this error
AttributeError: module ‘dolfinx’ has no attribute ‘has_petsc’

We can’t be of much more help unless you tell us how you installed dolfinx.

Do I need to install C++ core before pip install. If yes could you please elaborate on it as the instructions on the website are not descriptive enough for me. Apologies for my ignorance

You may want to follow one of the ways described in GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment . If you are new to dolfinx, I would suggest using a binary installation.

This thread is going off-topic from the original message. I am going to close this, and if you have further installation questions you can open a new topic.