From 850911776e55eba8b306581eb9d10f9be7fb2164 Mon Sep 17 00:00:00 2001 From: Frederic Petrignani Date: Sat, 3 Oct 2026 09:13:25 +0200 Subject: [PATCH 1/2] CMakeLists.txt: locate pyscf with the build interpreter, from the build directory, or fail Reworked along the review of 25 September: the pyscf lookup stays in one place (pyscf/lib/CMakeLists.txt) and runs with the interpreter the build runs under (find_package(Python); setup.py passes -DPython_EXECUTABLE=sys.executable), from the build directory instead of the checkout, and fails with a clear message when pyscf is not found or has no lib/config.h.in. PYSCF_SOURCE_DIR is a CACHE PATH instead of an option(). cmake_minimum_required 3.5 -> 3.12 for find_package(Python). Configure step tested on Linux (CMake 4.2): - /usr/bin/python3 (no pyscf) first on PATH, run from the checkout, no -DPython_EXECUTABLE: before, "Include pyscf source dir: /pyscf" and config.h.in does not exist; now, "Could not locate an installed pyscf using /usr/bin/python3". - -DPython_EXECUTABLE=/bin/python: "Include pyscf source dir: /site-packages/pyscf", configuring done. --- pyscf/lib/CMakeLists.txt | 19 +++++++++++++++---- setup.py | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) mode change 100755 => 100644 setup.py diff --git a/pyscf/lib/CMakeLists.txt b/pyscf/lib/CMakeLists.txt index 67bc57acd..65508b4e5 100644 --- a/pyscf/lib/CMakeLists.txt +++ b/pyscf/lib/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.5) +cmake_minimum_required (VERSION 3.12) project (pyscf_forge) # Build only the GAS FCI kernel library. This mode is intended for @@ -93,11 +93,22 @@ if(ENABLE_OPENMP) endif() endif() -option(PYSCF_SOURCE_DIR "Pyscf source directory e.g. /usr/local/lib/python3.7/site-packages/pyscf") +set(PYSCF_SOURCE_DIR "" CACHE PATH "Pyscf source directory e.g. /usr/local/lib/python3.7/site-packages/pyscf") if(NOT PYSCF_SOURCE_DIR) + # Locate the installed pyscf with the interpreter the build runs under (setup.py passes -DPython_EXECUTABLE), + # from the build directory: run from the checkout, an interpreter without pyscf would import the checkout's own + # namespace-package portion pyscf/ and answer with the wrong directory, silently. + find_package(Python COMPONENTS Interpreter REQUIRED) execute_process( - COMMAND python3 -c "import pyscf; print(pyscf.__path__[0], end='')" - OUTPUT_VARIABLE PYSCF_SOURCE_DIR) + COMMAND ${Python_EXECUTABLE} -c "import pyscf; print(pyscf.__path__[0], end='')" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + OUTPUT_VARIABLE PYSCF_SOURCE_DIR + RESULT_VARIABLE _pyscf_rc) + if(NOT _pyscf_rc EQUAL 0 OR NOT EXISTS "${PYSCF_SOURCE_DIR}/lib/config.h.in") + message(FATAL_ERROR + "Could not locate an installed pyscf using ${Python_EXECUTABLE}. " + "Pass -DPYSCF_SOURCE_DIR=<.../site-packages/pyscf> or -DPython_EXECUTABLE=.") + endif() endif() message(STATUS "Include pyscf source dir: ${PYSCF_SOURCE_DIR}") include_directories(${PYSCF_SOURCE_DIR}/lib ${PYSCF_SOURCE_DIR}/lib/deps/include) diff --git a/setup.py b/setup.py old mode 100755 new mode 100644 index 7cd3a4a19..c4ca84a3f --- a/setup.py +++ b/setup.py @@ -98,6 +98,9 @@ def run(self): self.announce('Configuring extensions', level=3) src_dir = os.path.abspath(os.path.join(__file__, '..', 'pyscf', 'lib')) cmd = ['cmake', f'-S{src_dir}', f'-B{self.build_temp}'] + # The interpreter this build runs under: CMakeLists.txt asks it where pyscf is installed, so that the lookup + # does not depend on which python3 is first on PATH. + cmd.append(f'-DPython_EXECUTABLE={sys.executable}') # Allow user to disable OCCRI C extension build build_occri = os.getenv('BUILD_OCCRI', 'ON') From 84230dae1fc269f257ed852e518dcc4e350a852b Mon Sep 17 00:00:00 2001 From: Frederic Petrignani Date: Fri, 9 Oct 2026 18:24:26 +0200 Subject: [PATCH 2/2] CMakeLists.txt: cmake_minimum_required 3.15 (CMP0094: FindPython takes the first interpreter by location); setup.py keeps its executable bit --- pyscf/lib/CMakeLists.txt | 2 +- setup.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 setup.py diff --git a/pyscf/lib/CMakeLists.txt b/pyscf/lib/CMakeLists.txt index 65508b4e5..77b4cd83a 100644 --- a/pyscf/lib/CMakeLists.txt +++ b/pyscf/lib/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.12) +cmake_minimum_required (VERSION 3.15) project (pyscf_forge) # Build only the GAS FCI kernel library. This mode is intended for diff --git a/setup.py b/setup.py old mode 100644 new mode 100755