Deploying Dolfinx and Python interfaces from source code on HPC

Dear all,
I am deploying Dolfinx and Python interfaces from source code on HPC.
I have install dolfinx successfully.Including successful linking to PETSc library.
Because:

-- The following RECOMMENDED packages have been found:

 * PETSc, Portable, Extensible Toolkit for Scientific Computation, <https://petsc.org/>
   Linear and nonlinear solvers
 * ParMETIS (required version >= 4.0.2), Parallel Graph Partitioning and Fill-reducing Matrix Ordering, <http://glaros.dtc.umn.edu/gkhome/metis/parmetis/overview>
   Parallel graph partitioning

After that,I created a Python virtual environment using conda and activated it. Then I ran the following commands in the python/ directory:

pip install scikit-build-core
python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install
pip install --check-build-dependencies --no-build-isolation .

After that, I installed petsc4py:

export PETSC_DIR=$HOME/petsc
pip install petsc4py

However, when I run the following code:

import numpy as np
print('np is OK')
import dolfinx
from dolfinx import fem, io, mesh
from mpi4py import MPI
from petsc4py import PETSc
print('dolfinx is OK')

I get this error:

Traceback (most recent call last):
  File "/hpcdata/home/research/hzhang01/wh/dolfinx/cpp/test.py", line 3, in <module>
    import dolfinx
  File "/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/dolfinx/__init__.py", line 20, in <module>
    assert dolfinx.common.has_petsc4py
AssertionError

Could you describe your whole process here?
Is there a reason for installing DOLFINx outside of the conda env, and then creating the conda env to link the python interface?

Coul you also run the latter install:

with a -v flag to see the build output.

In general, for HPC applications, our spack packages are recommended over conda GitHub - FEniCS/spack-fenics: Spack package repository overlay for FEniCS Ā· GitHub

Thanks dokken.Unfortunately, the HPC system I am using does not have Spack, and I prefer not to use Conda to set up the DOLFINx environment
I will describe whole process.
On HPC, some module coule be load.

module load gcc/13.2.0
module load cmake/3.31.10  
module load mkl/2025.2
module load mpi/2021.16
module load anaconda3 

Some dependencies for dolfinx is install in $HOME
such that petsc :$HOME/petsc boost :$HOME/boost
They were all installed by me from source code.
I think the most important is FFcx. Since, I’m not sure. I will desctibe FFCx install process.

In the directory: $HOME/wh/download/ffcx/
I run

python3 -m venv ffcx-env 
source ffcx-env/bin/activate 
pip install numpy cffi 
pip install fenics-ffcx fenics-ufl fenics-basix 

fenics-basix==0.9.0 fenics-ffcx==0.9.0 fenics-ufl==2024.2.0

After that, Configure DOLFINx with CMake

cmake .. \
-DHDF5_ROOT=$HOME/hdf5 \
-DHDF5_PREFER_PARALLEL=TRUE \
-DPARMETIS_ROOT=$HOME/parmetis-install \
-DCMAKE_INSTALL_PREFIX=$HOME/dolfinx \
-DPython3_EXECUTABLE=$HOME/wh/download/ffcx/ffcx-env/bin/python \
-DCMAKE_MODULE_PATH=$HOME \
-DMETIS_ROOT=$HOME/metis_install \
-DBasix_DIR=$HOME/fenicsx-install/lib64/cmake/basix \
-DPARMETIS_TEST_RUNS=TRUE \
-DMETIS_LIBRARY=$HOME/metis_install/lib/libmetis.so \
-DMETIS_INCLUDE_DIR=$HOME/metis_install/include \
-DCMAKE_INCLUDE_PATH=$HOME/metis_install/include

obtan:

-- The C compiler identification is GNU 11.4.1
-- The CXX compiler identification is GNU 11.4.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found MPI_C: /public/software/oneapi-2025.2/mpi/2021.16/lib/libmpi.so (found suitable version "4.1", minimum required is "3")
-- Found MPI_CXX: /public/software/oneapi-2025.2/mpi/2021.16/lib/libmpicxx.so (found suitable version "4.1", minimum required is "3")
-- Found MPI: TRUE (found suitable version "4.1", minimum required is "3")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Performing Test HAVE_PIPE
-- Performing Test HAVE_PIPE - Success
-- Performing Test HAVE_PEDANTIC
-- Performing Test HAVE_PEDANTIC - Success
-- Performing Test HAVE_DEBUG
-- Performing Test HAVE_DEBUG - Success
-- Performing Test HAVE_O2_OPTIMISATION
-- Performing Test HAVE_O2_OPTIMISATION - Success
-- Found Boost 1.84.0 at /hpcdata/home/research/hzhang01/boost/lib/cmake/Boost-1.84.0
--   Requested configuration: REQUIRED COMPONENTS timer
-- Found boost_headers 1.84.0 at /hpcdata/home/research/hzhang01/boost/lib/cmake/boost_headers-1.84.0
-- Found boost_timer 1.84.0 at /hpcdata/home/research/hzhang01/boost/lib/cmake/boost_timer-1.84.0
--   [x] libboost_timer.so.1.84.0
--   [ ] libboost_timer.a
-- Adding boost_timer dependencies: headers
-- Checking for Basix hints with /hpcdata/home/research/hzhang01/wh/download/ffcx/ffcx-env/bin/python
-- Adding /hpcdata/home/research/hzhang01/wh/download/ffcx/ffcx-env/lib64/python3.9/site-packages/basix to Basix search hints
-- Found HDF5 at /hpcdata/home/research/hzhang01/hdf5/cmake via NO_MODULE. Now trying to extract locations etc.
-- Trying to get properties of target hdf5-shared
-- Found imported configurations: NOCONFIG
-- Start search through imported configurations in the following order: RelWithDebInfo;RELWITHDEBINFO;RELEASE;DEBUG;NOCONFIG
-- Selected imported configuration: NOCONFIG
-- Found HDF5: hdf5-shared (found version "1.14.3") found components: C
-- HDF5_DIR: /hpcdata/home/research/hzhang01/hdf5/cmake
-- HDF5_DEFINITIONS: 
-- HDF5_INCLUDE_DIRS: /hpcdata/home/research/hzhang01/hdf5/include
-- HDF5_LIBRARIES: hdf5-shared
-- HDF5_HL_LIBRARIES: 
-- HDF5_C_DEFINITIONS: 
-- HDF5_C_INCLUDE_DIR: 
-- HDF5_C_INCLUDE_DIRS: /hpcdata/home/research/hzhang01/hdf5/include
-- HDF5_C_LIBRARY: /hpcdata/home/research/hzhang01/hdf5/lib/libhdf5.so.310.3.0
-- HDF5_C_LIBRARIES: hdf5-shared
-- HDF5_C_HL_LIBRARY: 
-- HDF5_C_HL_LIBRARIES: 
-- Defined targets (if any):
-- ... hdf5::hdf5
-- ... hdf5-static
-- ... hdf5-shared
-- ... hdf5_hl-static
-- ... hdf5_hl-shared
-- Found Python3: /hpcdata/home/research/hzhang01/wh/download/ffcx/ffcx-env/bin/python (found version "3.9.18") found components: Interpreter
-- Asking Python module FFCx for location of ufcx.h...
-- Found UFCx: /hpcdata/home/research/hzhang01/wh/download/ffcx/ffcx-env/lib64/python3.9/site-packages/ffcx/codegeneration (found suitable version "0.9.0", minimum required is "0.9")
CMake Warning at CMakeLists.txt:406 (find_package):
  By not providing "FindADIOS2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "ADIOS2", but
  CMake did not find one.

  Could not find a package configuration file provided by "ADIOS2" (requested
  version 2.8.1) with any of the following names:

    ADIOS2Config.cmake
    adios2-config.cmake

  Add the installation prefix of "ADIOS2" to CMAKE_PREFIX_PATH or set
  "ADIOS2_DIR" to a directory containing one of the above files.  If "ADIOS2"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Found PkgConfig: /usr/bin/pkg-config (found version "1.7.3")
-- Checking for one of the modules 'OPTIONAL;PETSc>=3.15;petsc>=3.15'
-- Found PETSc version 3.25.0, prefix: /hpcdata/home/research/hzhang01/petsc
-- Checking for one of the modules 'slepc>=3.15'
-- Could NOT find SCOTCH (missing: SCOTCH_DIR)
-- Checking for package 'SCOTCH-PT'
-- SCOTCH could not be found. Be sure to set SCOTCH_DIR. (missing: SCOTCH_LIBRARIES SCOTCH_INCLUDE_DIRS SCOTCH_TEST_RUNS) 
CMake Warning (dev) at CMakeLists.txt:491 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  CMake variable PARMETIS_ROOT is set to:

    /hpcdata/home/research/hzhang01/parmetis-install

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found ParMETIS: /hpcdata/home/research/hzhang01/parmetis-install/lib/libparmetis.so;/hpcdata/home/research/hzhang01/metis_install/lib/libmetis.so (Required is at least version "4.0.2")
-- Checking for package 'KaHIP'
-- KaHIP could not be found/configured. (missing: KAHIP_INCLUDE_DIRS KAHIP_LIBRARIES KAHIP_TEST_RUNS) 
-- The following features have been enabled:

 * BUILD_SHARED_LIBS, Build DOLFINx with shared libraries.
 * CMAKE_INSTALL_RPATH_USE_LINK_PATH, Add paths to linker search and installed rpath.
 * DOLFINX_BASIX_PYTHON, Ask Python basix module for hint where to find Basix C++ install using CONFIG mode.
 * DOLFINX_UFCX_PYTHON, Ask Python FFCx module where to find ufcx.h header using MODULE mode. Otherwise use CONFIG mode.

-- The following RECOMMENDED packages have been found:

 * PETSc, Portable, Extensible Toolkit for Scientific Computation, <https://petsc.org/>
   Linear and nonlinear solvers
 * ParMETIS (required version >= 4.0.2), Parallel Graph Partitioning and Fill-reducing Matrix Ordering, <http://glaros.dtc.umn.edu/gkhome/metis/parmetis/overview>
   Parallel graph partitioning

-- The following REQUIRED packages have been found:

 * Threads
 * spdlog
 * pugixml
 * boost_headers (required version == 1.84.0)
 * boost_timer (required version == 1.84.0)
 * Boost (required version >= 1.70), Boost C++ libraries, <http://www.boost.org>
 * Basix (required version >= 0.8)
 * MPI
 * HDF5, Hierarchical Data Format 5 (HDF5), <https://www.hdfgroup.org/HDF5>
 * Python3
 * UFCx (required version >= 0.9), Interface for form-compilers (part of FFCx), <https://github.com/fenics/ffcx>
 * PkgConfig

-- The following features have been disabled:

 * INSTALL_RUNTIME_DEPENDENCIES, Include runtime dependencies in install (Windows-only)
 * DOLFINX_SKIP_BUILD_TESTS, Skip build tests for testing usability of dependency packages.

-- The following OPTIONAL packages have not been found:

 * ADIOS2 (required version >= 2.8.1), Adaptable Input/Output (I/O) System., <https://adios2.readthedocs.io/en/latest/>
   IO, including in parallel
 * SCOTCH, Programs and libraries for graph, mesh and hypergraph partitioning, <https://www.labri.fr/perso/pelegrin/scotch>
   Parallel graph partitioning
 * KaHIP, A family of graph partitioning programs, <https://kahip.github.io/>
   Parallel graph partitioning

-- The following RECOMMENDED packages have not been found:

 * SLEPc, Scalable Library for Eigenvalue Problem Computations, <http://slepc.upv.es/>
   Eigenvalue computation

-- Configuring done (2.8s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    METIS_INCLUDE_DIR
    METIS_ROOT


-- Build files have been written to: /hpcdata/home/research/hzhang01/wh/dolfinx/cpp/build

METIS_INCLUDE_DIR METIS_ROOTwere not used.But I think is unimportant.

After that,I created a Python virtual environment using conda and activated it.

conda create --name wh_dolfinx python=3.10
conda activate  wh_dolfinx

Then I ran the following commands in the python/ directory: As describe Installation — DOLFINx 0.11.0.dev0 documentation

pip install scikit-build-core
python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install
pip install --check-build-dependencies --no-build-isolation .

There are some message that you want:

(wh_dolfinx) [hzhang01@login python]$ pip install -v --check-build-dependencies --no-build-isolation .
Using pip 26.0.1 from /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/pip (python 3.10)
Processing ./.
  Running command Preparing metadata (pyproject.toml)
  2026-04-10 20:44:35,603 - scikit_build_core - WARNING - Could not determine CMake version via --version, got '' '/usr/bin/cmake3: symbol lookup error: /lib64/libldap.so.2: undefined symbol: EVP_md2, version OPENSSL_3.0.0\n'
  *** scikit-build-core 0.12.2 using CMake 3.31.10 (metadata_wheel)
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.21 in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from fenics-dolfinx==0.9.0) (2.2.6)
Requirement already satisfied: cffi<1.17 in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from fenics-dolfinx==0.9.0) (1.16.0)
Requirement already satisfied: mpi4py in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from fenics-dolfinx==0.9.0) (4.1.1)
Requirement already satisfied: fenics-basix<0.10.0,>=0.9.0 in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from fenics-dolfinx==0.9.0) (0.9.0)
Requirement already satisfied: fenics-ffcx<0.10.0,>=0.9.0 in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from fenics-dolfinx==0.9.0) (0.9.0)
Requirement already satisfied: fenics-ufl<2024.3.0,>=2024.2.0 in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from fenics-dolfinx==0.9.0) (2024.2.0)
Requirement already satisfied: pycparser in /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages (from cffi<1.17->fenics-dolfinx==0.9.0) (3.0)
Building wheels for collected packages: fenics-dolfinx
  Running command Building wheel for fenics-dolfinx (pyproject.toml)
  2026-04-10 20:44:35,801 - scikit_build_core - WARNING - Could not determine CMake version via --version, got '' '/usr/bin/cmake3: symbol lookup error: /lib64/libldap.so.2: undefined symbol: EVP_md2, version OPENSSL_3.0.0\n'
  *** scikit-build-core 0.12.2 using CMake 3.31.10 (wheel)
  *** Configuring CMake...
  loading initial cache file /tmp/tmpawr_to4p/build/CMakeInit.txt
  -- The C compiler identification is GNU 13.2.0
  -- The CXX compiler identification is GNU 13.2.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /public/software/gcc-13.2.0/bin/gcc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /public/software/gcc-13.2.0/bin/g++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Found Python: /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/bin/python3.10 (found version "3.10.20") found components: Interpreter Development Development.Module Development.Embed
  -- Found MPI_C: /public/software/oneapi-2025.2/mpi/2021.16/lib/libmpi.so (found version "4.1")
  -- Found MPI_CXX: /public/software/oneapi-2025.2/mpi/2021.16/lib/libmpicxx.so (found version "4.1")
  -- Found MPI: TRUE (found version "4.1")
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
  -- Found Threads: TRUE
  -- Found Boost 1.84.0 at /hpcdata/home/research/hzhang01/boost/lib/cmake/Boost-1.84.0
  --   Requested configuration: REQUIRED COMPONENTS timer
  -- Found boost_headers 1.84.0 at /hpcdata/home/research/hzhang01/boost/lib/cmake/boost_headers-1.84.0
  -- Found boost_timer 1.84.0 at /hpcdata/home/research/hzhang01/boost/lib/cmake/boost_timer-1.84.0
  --   [x] libboost_timer.so.1.84.0
  --   [ ] libboost_timer.a
  -- Adding boost_timer dependencies: headers
  -- Checking for Basix hints with /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/bin/python3.10
  -- Adding /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/basix to Basix search hints
  -- Found HDF5 at /hpcdata/home/research/hzhang01/hdf5/cmake via NO_MODULE. Now trying to extract locations etc.
  -- Trying to get properties of target hdf5-shared
  -- Found imported configurations: NOCONFIG
  -- Start search through imported configurations in the following order: Release;RELWITHDEBINFO;RELEASE;DEBUG;NOCONFIG
  -- Selected imported configuration: NOCONFIG
  -- Found HDF5: hdf5-shared (found version "1.14.3") found components: C
  -- HDF5_DIR: /hpcdata/home/research/hzhang01/hdf5/cmake
  -- HDF5_DEFINITIONS:
  -- HDF5_INCLUDE_DIRS: /hpcdata/home/research/hzhang01/hdf5/include
  -- HDF5_LIBRARIES: hdf5-shared
  -- HDF5_HL_LIBRARIES:
  -- HDF5_C_DEFINITIONS:
  -- HDF5_C_INCLUDE_DIR:
  -- HDF5_C_INCLUDE_DIRS: /hpcdata/home/research/hzhang01/hdf5/include
  -- HDF5_C_LIBRARY: /hpcdata/home/research/hzhang01/hdf5/lib/libhdf5.so.310.3.0
  -- HDF5_C_LIBRARIES: hdf5-shared
  -- HDF5_C_HL_LIBRARY:
  -- HDF5_C_HL_LIBRARIES:
  -- Defined targets (if any):
  -- ... hdf5::hdf5
  -- ... hdf5-static
  -- ... hdf5-shared
  -- ... hdf5_hl-static
  -- ... hdf5_hl-shared
  -- Found PkgConfig: /usr/bin/pkg-config (found version "1.7.3")
  -- Checking for one of the modules 'PETSc;petsc'
  -- Found DOLFINx at /hpcdata/home/research/hzhang01/dolfinx/lib64/cmake/dolfinx
  -- Found petsc4py include directory at /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/petsc4py/include
  -- Found mpi4py include directory at /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/mpi4py/include
  -- Configuring done (1.6s)
  -- Generating done (0.0s)
  -- Build files have been written to: /tmp/tmpawr_to4p/build
  *** Building project with Ninja...
  [1/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/dolfinx.cpp.o
  [2/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/nb_static_property.cpp.o
  [3/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/implicit.cpp.o
  [4/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/trampoline.cpp.o
  [5/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/error.cpp.o
  [6/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/nb_internals.cpp.o
  [7/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/nb_ndarray.cpp.o
  [8/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/common.cpp.o
  [9/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/nb_enum.cpp.o
  [10/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/nb_func.cpp.o
  [11/24] Building CXX object CMakeFiles/nanobind-static.dir/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/nanobind/src/nb_type.cpp.o
  [12/24] Linking CXX static library libnanobind-static.a
  [13/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/log.cpp.o
  [14/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/graph.cpp.o
  [15/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/common.cpp.o
  [16/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/io.cpp.o
  [17/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/geometry.cpp.o
  [18/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/refinement.cpp.o
  [19/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/petsc.cpp.o
  [20/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/la.cpp.o
  [21/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/mesh.cpp.o
  [22/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/fem.cpp.o
  [23/24] Building CXX object CMakeFiles/cpp.dir/dolfinx/wrappers/assemble.cpp.o
  [24/24] Linking CXX shared module cpp.cpython-310-x86_64-linux-gnu.so
  *** Installing project into wheel...
  -- Install configuration: "Release"
  -- Installing: /tmp/tmpawr_to4p/wheel/platlib/dolfinx/cpp.cpython-310-x86_64-linux-gnu.so
  -- Set non-toolchain portion of runtime path of "/tmp/tmpawr_to4p/wheel/platlib/dolfinx/cpp.cpython-310-x86_64-linux-gnu.so" to "/hpcdata/home/research/hzhang01/dolfinx/lib64:/hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/basix/lib:/hpcdata/home/research/hzhang01/boost/lib:/hpcdata/home/research/hzhang01/hdf5/lib:/hpcdata/home/research/hzhang01/petsc/lib"
  *** Making wheel...
  *** Created fenics_dolfinx-0.9.0-cp310-cp310-linux_x86_64.whl
  Building wheel for fenics-dolfinx (pyproject.toml) ... done
  Created wheel for fenics-dolfinx: filename=fenics_dolfinx-0.9.0-cp310-cp310-linux_x86_64.whl size=1721393 sha256=e8ff9513cf7a4122bc65a7d26cdc48e9ac55f1f3c6aa0921dcb5bf2b040531c4
  Stored in directory: /tmp/pip-ephem-wheel-cache-cnr1z9lz/wheels/bf/ac/e5/ce526b019af8b28c73afba4bfbbe1cf28ab0d946e5e9881652
Successfully built fenics-dolfinx
Installing collected packages: fenics-dolfinx
  Attempting uninstall: fenics-dolfinx
    Found existing installation: fenics-dolfinx 0.9.0
    Uninstalling fenics-dolfinx-0.9.0:
      Removing file or directory /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/dolfinx/
      Removing file or directory /hpcdata/home/research/hzhang01/.conda/envs/wh_dolfinx/lib/python3.10/site-packages/fenics_dolfinx-0.9.0.dist-info/
      Successfully uninstalled fenics-dolfinx-0.9.0
Successfully installed fenics-dolfinx-0.9.0

After that, I installed petsc4py:

pip install petsc4py

It seems like there’s no error again, and I’m not sure why. It might have been rerun

pip install -v --check-build-dependencies --no-build-isolation .

Here you can see that it found petsc4py when building the Python interface. This was likely your problem before, if you install petsc4py after the dolfinx Python interface you don’t get the right bindings

Dear dokken,I encountered the same problem in:
DOLFINx 0.9 tutorial example: functionspace(…, (ā€œLagrangeā€, 1)) raises TypeError - installation - FEniCS Project
But I didn’t understand what it meant?

You mean that should I also import my conda environment wh_rolfinx when installing Basix and Dolfinx with source code?
When I installed Basix in the source code, the environment at this time was base or not wh_dolfinx.

I would install basix and DOLFINx with the same python environment (as basix has both a C++ and Python interface), which both uses nanobind. Nanobind is very specific about its ABI compatibility when mixing bindings.

Thank you dokken very much.
I find problem that I only in dolfinx/python runs:

pip install --check-build-dependencies --no-build-isolation .

In fact, before compiling Dolfinx, I need to install the Python interface of Basix.
In basix/python runs:

pip install --check-build-dependencies --no-build-isolation .

Yes. You have to install basix prior to installing DOLFINx. But they should use the same build dependencies (which includes nanobind to ensure ABI compatibility.)