auderson
auderson

Reputation: 119

arrow::py::import_pyarrow() cause a SEGMENTATION FAULT

I'm trying to use arrow-cpp to build a Table then transfer it back to python.

In order to do that, I need to call arrow::py::import_pyarrow() beforehand, but this will cause a SEGFAULT.

Can anyone help to find where I did wrong?

here is a minimal example

CMakeLists.txt

cmake_minimum_required(VERSION 3.20.0)
project(TEST)
set(CMAKE_CXX_STANDARD 17)
set(Python3_EXECUTABLE "/home/auderson/miniconda3/bin/python3.8")

list(APPEND CMAKE_PREFIX_PATH "/home/auderson/miniconda3/lib/cmake/arrow")
find_package(Arrow REQUIRED)
find_package(ArrowPython REQUIRED)
find_package(Python3 COMPONENTS Interpreter Development)


include_directories(.
        /home/auderson/miniconda3/lib/python3.8/site-packages/pyarrow/include
        ${Python3_INCLUDE_DIRS})

add_executable(TEST
        mini_t.cpp
        )

target_link_libraries(${PROJECT_NAME} PRIVATE arrow_shared)
target_link_libraries(${PROJECT_NAME} PRIVATE arrow_python_shared)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Python3_LIBRARIES})

cpp file


#include "arrow/python/pyarrow.h"

int main() {
    return arrow::py::import_pyarrow();
}


output(debug mode)

Signal: SIGSEGV (Segmentation fault)

Process finished with exit code 1

if not in debug mode:

Process finished with exit code 139

other functionalities of arrow work just fine.

Upvotes: 0

Views: 1269

Answers (1)

Wes McKinney
Wes McKinney

Reputation: 105521

The C++ application does not initialize the Python interpreter. Here's an example C++ executable which does this correctly:

https://github.com/apache/arrow/blob/8e43f23dcc6a9e630516228f110c48b64d13cec6/cpp/src/arrow/python/util/test_main.cc

This was also answered on

https://lists.apache.org/thread.html/ra6a5d523a1cf9a305ae9a57d7abb8d5afdfa252487165858aa24e323%40%3Cuser.arrow.apache.org%3E

Upvotes: 6

Related Questions