ROOT with Anaconda -> CMake causes library clashes

Hi,

In my team we use PyROOT with Anaconda. We do a manual ROOT installation. When compiling ROOT with Anaconda’s Python version, we find that ROOT’s CMake causes Python library clashes. For the following reason:

The path of the Python installation found by the SearchInstalledSoftware CMake module is automatically appended to the “CMAKE_PREFIX_PATH” variable. As a result, subsequent searches for external libraries include this path, and libraries from the Python installation are picked up. When using Python from Anaconda, this involves libraries such as “readline”, “crypto”, and “ssl”.

Linking to Anaconda libraries forces users to append the Anaconda directory to the search path for shared libraries, which makes system programs such as “wget”, “curl”, “ssh”, and “gpg” load Anaconda libraries as well. This gives problems if the system libraries have the same versions as the Anaconda libraries, but are slightly different.

We wrote a patch to CMake to avoid linking to libs from the Python install. See below. In the patch, the Python installation directory is not automatically appended to the CMAKE_PREFIX_PATH any more. If libraries or headers from this installation are required for ROOT, the paths of these components can be specified explicitly when configuring the ROOT installation.

This may not be proper code to put in ROOT as is, but we are curious to hear what the core developer(s) have to say about this issue, and how you plan to fix it.

Many thanks,
-Max

PS git diff wrt today’s master branch:


cmake/modules/SearchInstalledSoftware.cmake | 1 -
1 file changed, 1 deletion(-)

diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake
index 67d618f…2448d8c 100644
— a/cmake/modules/SearchInstalledSoftware.cmake
+++ b/cmake/modules/SearchInstalledSoftware.cmake
@@ -434,7 +434,6 @@ if(python OR python3)
message(STATUS “Found Python interpreter version ${PYTHON_VERSION}”)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys;sys.stdout.write(sys.prefix)"
OUTPUT_VARIABLE PYTHON_PREFIX)

  • set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PYTHON_PREFIX})
    endif()
    set(Python_ADDITIONAL_VERSIONS ${PYTHON_VERSION})
    find_package(PythonLibs)

    2.9.3

The reason for adding the prefix where the Python interpreter is found to CMAKE_PREFIX_PATH is to ensure that the Python library belongs to the same installation as the Python interpreter. We had problems in the past with these inconsistencies.
I have seen now that from CMake version 3.1.3 they have added the following statement in their documentation:

If also calling find_package(PythonInterp), call find_package(PythonInterp) first to get the currently active Python version by default with a consistent version of PYTHON_LIBRARIES.

So, I think it is now safe to remove the line in question. I’ll commit the changes in master branch.

To be save, I also set the path of the NumPy headers after removing the CMAKE_PREFIX_PATH line, in addition to the path of the Python executable:

-DPYTHON_EXECUTABLE="/opt/anaconda/4.1.1/bin/python"
-DNUMPY_INCLUDE_DIR="/opt/anaconda/4.1.1/lib/python3.5/site-packages/numpy/core/include"