I modified it and it resulted with the same error message.
I initially installed DOLFINx from source without PETSc, and it worked without any issues. Later, I installed PETSc via Homebrew and petsc4py via pip, then reinstalled DOLFINx from the source. After that, I encountered this error.
Did you make sure to clear your old dolfinx include files fully?
Also, if the dolfinx code above when you did not have PETSC installed, you must have had a PETSC installation somewhere else, as LinearProblem relies on PETSC and petsc4py.