PETSc_api.h error when installing dolfinx main branch python from source

~/dolfinx/python/pip install .

      Testing: /home/prusso/.local/lib/python3.10/site-packages/basix
      -- Found MPI_C: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so (found version "3.1")
      -- Found MPI_CXX: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so (found version "3.1")
      -- Found MPI: TRUE (found version "3.1")
      -- Found Boost 1.74.0 at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0
      --   Requested configuration: QUIET REQUIRED COMPONENTS timer;filesystem
      -- Found boost_headers 1.74.0 at /usr/lib/x86_64-linux-gnu/cmake/boost_headers-1.74.0
      -- Found boost_timer 1.74.0 at /usr/lib/x86_64-linux-gnu/cmake/boost_timer-1.74.0
      --   [x] libboost_timer.so.1.74.0
      --   [ ] libboost_timer.a
      -- Adding boost_timer dependencies: chrono;headers
      -- Found boost_chrono 1.74.0 at /usr/lib/x86_64-linux-gnu/cmake/boost_chrono-1.74.0
      --   [x] libboost_chrono.so.1.74.0
      --   [ ] libboost_chrono.a
      -- Adding boost_chrono dependencies: headers
      -- Found boost_filesystem 1.74.0 at /usr/lib/x86_64-linux-gnu/cmake/boost_filesystem-1.74.0
      --   [x] libboost_filesystem.so.1.74.0
      --   [ ] libboost_filesystem.a
      -- Adding boost_filesystem dependencies: headers
      -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found suitable version "1.74.0", minimum required is "1.70") found components: timer filesystem
      -- Found Python3: /usr/bin/python3 (found version "3.10.12") found components: Interpreter
      -- Adding /home/prusso/.local/lib/python3.10/site-packages/basix to Basix search hints
      -- HDF5: Using hdf5 compiler wrapper to determine C configuration
      -- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/openmpi/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.7") found components: C
      -- HDF5_DIR: HDF5_DIR-NOTFOUND
      -- HDF5_DEFINITIONS:
      -- HDF5_INCLUDE_DIRS: /usr/include/hdf5/openmpi
      -- HDF5_LIBRARIES: /usr/lib/x86_64-linux-gnu/hdf5/openmpi/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so
      -- HDF5_HL_LIBRARIES:
      -- HDF5_C_DEFINITIONS:
      -- HDF5_C_INCLUDE_DIR:
      -- HDF5_C_INCLUDE_DIRS: /usr/include/hdf5/openmpi
      -- HDF5_C_LIBRARY:
      -- HDF5_C_LIBRARIES: /usr/lib/x86_64-linux-gnu/hdf5/openmpi/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so
      -- HDF5_C_HL_LIBRARY:
      -- HDF5_C_HL_LIBRARIES:
      -- Defined targets (if any):
      -- ... hdf5::hdf5
      -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
      -- Checking for one of the modules 'PETSc;petsc'
      -- Performing Test HAVE_PEDANTIC
      -- Performing Test HAVE_PEDANTIC - Success
      -- Found petsc4py include directory at /home/prusso/.local/lib/python3.10/site-packages/petsc4py/include
      -- Found mpi4py include directory at /home/prusso/.local/lib/python3.10/site-packages/mpi4py/include
      -- Configuring done
      -- Generating done
      CMake Warning:
        Manually-specified variables were not used by the project:
      
          Python3_LIBRARIES
      
      
      -- Build files have been written to: /home/prusso/dolfinx/python/build/temp.linux-x86_64-3.10
      [ 23%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/assemble.cpp.o
      [ 23%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/dolfinx.cpp.o
      [ 23%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/common.cpp.o
      [ 30%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/fem.cpp.o
      [ 38%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/geometry.cpp.o
      [ 46%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/graph.cpp.o
      [ 53%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/io.cpp.o
      [ 61%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/la.cpp.o
      [ 69%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/log.cpp.o
      [ 76%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/mesh.cpp.o
      [ 84%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/petsc.cpp.o
      [ 92%] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/refinement.cpp.o
      In file included from /home/prusso/.local/lib/python3.10/site-packages/petsc4py/include/petsc4py/../../PETSc_api.h:9,
                       from /home/prusso/.local/lib/python3.10/site-packages/petsc4py/include/petsc4py/petsc4py.h:10,
                       from /home/prusso/dolfinx/python/dolfinx/wrappers/caster_petsc.h:9,
                       from /home/prusso/dolfinx/python/dolfinx/wrappers/petsc.cpp:9:
      /home/prusso/.local/lib/python3.10/site-packages/petsc4py/include/petsc4py/../../PETSc.h:105:3: error: ‘PetscDevice’ does not name a type; did you mean ‘PetscDefined’?

For the current main branch the cpp compiled and installed. For some reason just for main branch I have this PETSc.h error. The v0.6.0’s python does work with pip install .

Anyone maybe know how to resolve this for Ubuntu jammy desktop?

What version of petsc4py and petsc are you running?

It doesn’t seem like there is anything that has changed Since the 0.6 release History for python/dolfinx/wrappers/caster_petsc.h - FEniCS/dolfinx · GitHub

So what I did to solve this problem is:

pip uninstall mpi4py, petsc4py and remove petsc stuff from ~/.local/lib/…/site-packages/petsc*

Then I used spack to install main branch and activated the environment in the terminal. The main branch needs I think a version of petsc4py not available from apt at the current time…