Ignoring Anaconda Python prefix

My user audience often has Anaconda Python installed with Shared libraries on Path that are not ABI compatible with the desired compiler.

Example: python h5py package needs libhdf5.so to work in Python, but for my compiled programs I can’t use Anaconda libhdf5.so, yet I need Anaconda Python on Path.

This is easily solved by setting in CMakeLists.txt AFTER find_package(Python) but before any other find_package() calls:

# exclude Anaconda directories from search
if(DEFINED ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
endif()

set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH false)

reference:

I have found this preferable to avoid totally ignoring env var PATH:

# exclude Anaconda directories from search
if(DEFINED ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin)
  # need CMAKE_IGNORE_PATH for CMake < 3.23
  # and to ensure system env var PATH doesn't interfere
  # despite CMAKE_IGNORE_PREFIX_PATH
endif()