Build Slicer with the system Python

Hi,

I am trying to build Slicer and I want to use as many -DSlicer_USE_SYSTEM_***=1 as possible.
I provide all the dependencies with conda.

My conda environment is activated and there I have Python 3.13.1 installed, together with packaging and many more packages.

I use the following command to generate the build files:

cmake -S . -B build  \
    -DCMAKE_C_COMPILER=$CC \
    -DCMAKE_CXX_COMPILER=$CXX \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS $LDFLAGS" \
    -DCMAKE_C_FLAGS="$CFLAGS $LDFLAGS" \
    -DSlicer_FORCED_REVISION="12345678" \
    -Wno-dev \
    -DSlicer_USE_SYSTEM_LZMA=1 \
    -DSlicer_USE_SYSTEM_zlib=1 \
    -DSlicer_USE_SYSTEM_bzip2=1 \
    -DSlicer_USE_SYSTEM_curl=1 \
    -DSlicer_USE_SYSTEM_LibFFI=1 \
    -DSlicer_USE_SYSTEM_DCMTK=1 \
    -DSlicer_USE_SYSTEM_OpenSSL=1 \
    -DSlicer_USE_SYSTEM_LibArchive=1 \
    -DSlicer_USE_SYSTEM_Swig=1 \
    -DSlicer_USE_SimpleITK_SHARED="ON" \
    -DSlicer_VTK_SMP_IMPLEMENTATION_TYPE="TBB" \
    -DBUILD_TESTING="OFF" \
    -DCMAKE_MESSAGE_LOG_LEVEL=ERROR \
    -DSlicer_USE_SYSTEM_python=1 \
    -DPYTHON_EXECUTABLE:FILEPATH="/home/mgrigorov/git/slicer/.pixi/envs/default/bin/python3" \
    -DSlicer_USE_SYSTEM_python-pythonqt-requirements=1

But it fails with:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'packaging'
CMake Error at CMake/ExternalProjectDependencyForPython.cmake:111 (message):
  Could not import module for required dependency 'packaging' using
  '/usr/bin/python3.9' interpreter.
Call Stack (most recent call first):
  SuperBuild/External_python-pythonqt-requirements.cmake:24 (ExternalProject_FindPythonPackage)
  CMake/ExternalProjectDependency.cmake:890 (include)
  CMake/ExternalProjectDependency.cmake:964 (ExternalProject_Include_Dependencies)
  SuperBuild.cmake:473 (ExternalProject_Include_Dependencies)
  CMakeLists.txt:779 (include)


-- Configuring incomplete, errors occurred!

It seems it ignores the PYTHON_EXECUTABLE setting…
/home/mgrigorov/git/slicer/.pixi/envs/default/bin/ is the first entry in $PATH, so both python and python3 are used from there.

Any idea why cmake tries to use /usr/bin/python3.9 instead ?

P.S. If I try to use the vendored Python, i.e. -DSlicer_USE_SYSTEM_python=0 then it installs SlicerPython that is for x86_64 while I run it on Linux aarch64 system.

1 Like