Does CMake support Python3?

I cannot create a Python shell module for my C library through CMake and Swig for Python3. Everything works fine for Python2.x, but it looks like CMake can't find Python3. I already looked around and tried a couple of things.

For example, my python executable links to Python3, since I read CMake, it will first find this version.

See here the part of SWIG CMakeLists.txt :

 FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) FIND_PACKAGE(PythonInterp 3) FIND_PACKAGE(PythonLibs 3) FIND_PATH(PYTHON_INCLUDE_PATH Python.h /usr/include /usr/local/include) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(CMAKE_SWIG_FLAGS "") SET_SOURCE_FILES_PROPERTIES(kissCT3.i PROPERTIES CPLUSPLUS ON) #SET_SOURCE_FILES_PROPERTIES(kissCT3.i PROPERTIES SWIG_FLAGS "-includeall -py3") SWIG_ADD_MODULE(kissCT3 python kissCT3.i) SWIG_LINK_LIBRARIES(kissCT3 libct2d matio kissfft ${PYTHON_LIBRARIES}) 

Unfortunately, the result after calling cmake shows that only python2.7 was found:

 -- Found SWIG: /usr/bin/swig2.0 (found version "2.0.4") -- Found PythonInterp: /usr/bin/python2.7 (Required is at least version "3") -- Found PythonLibs: /usr/lib/libpython2.7.so (Required is at least version "3") -- Configuring done -- Generating done 
+6
source share
3 answers

Can you make sure your build directory is clean? I had the same problem and after cleaning dir it worked.

+6
source

I kind of solved the problem by installing the python version manually. This is not recommended, but now it works (note that you must use your own installation path for the python version that you want to use):

 SET(PYTHON_INCLUDE_PATH /usr/include/python3.2mu) SET(PYTHON_LIBRARIES /usr/lib/libpython3.2mu.so) SET(PYTHON_EXECUTABLE /usr/bin/python3.2mu) SET(PYTHON_INCLUDE_DIR /usr/include/python3.2mu) 
+1
source

This is a known bug, but unfortunately it is not resolved at this point, see http://www.cmake.org/Bug/print_bug_page.php?bug_id=13794

0
source

Source: https://habr.com/ru/post/949633/


All Articles