Я хочу использовать CPYTHON C API, но все же получил это < /p> [code][component_container-1] Traceback (most recent call last): [component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/core/__init__.py", line 24, in [component_container-1] from . import multiarray [component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/core/multiarray.py", line 10, in [component_container-1] from . import overrides [component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/core/overrides.py", line 8, in [component_container-1] from numpy.core._multiarray_umath import ( [component_container-1] ImportError: /usr/local/lib/python3.10/dist-packages/numpy/core/_multiarray_umath.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyObject_SelfIter [component_container-1] [component_container-1] During handling of the above exception, another exception occurred: [component_container-1] [component_container-1] Traceback (most recent call last): [component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/__init__.py", line 130, in [component_container-1] from numpy.__config__ import show as show_config [component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/__config__.py", line 4, in [component_container-1] from numpy.core._multiarray_umath import ( [component_container-1] File "/usr/local/lib/python3.10/dist-packages/numpy/core/__init__.py", line 50, in [component_container-1] raise ImportError(msg) [component_container-1] ImportError: < /code> Мой текущий файл cmakelist < /p> set(My_Python_Version "3.10") find_package(Python ${My_Python_Version} EXACT COMPONENTS Interpreter Development NumPy REQUIRED) message(STATUS "Using Python: ${Python_EXECUTABLE}") message(STATUS "Python include: ${Python_INCLUDE_DIRS}") message(STATUS "Python numpy include: ${Python_NumPy_INCLUDE_DIRS}")
target_link_libraries(mynode ${OpenCV_LIBS} ${cpp_typesupport_target} ${ONNX_LIBS} ${TORCH_LIBS} ${Python_LIBRARIES} common_tool_lib ) target_include_directories(mynode PRIVATE /usr/local/onnxruntime/include /usr/local/libtorch/include /usr/local/libtorch/include/torch/csrc/api/include ${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS} ) < /code> Я пробовал различные методы и даже спросил несколько инструментов ИИ, но все еще не могу решить это, и, похоже, я должен отказаться от вызова кодов Python из моей среды C ++. Есть идеи?MyNode::MyNode(const rclcpp::NodeOptions& options) : BaseNode("perception_node", options), time_stamp_(0), tracking_module_(nullptr), tracking_function_(nullptr) {
// Initialize Python interpreter if (!Py_IsInitialized()) { Py_Initialize(); // Initialize numpy by importing it PyRun_SimpleString("import numpy"); }
tracking_module_ = PyImport_ImportModule("Track_infer"); if (!tracking_module_) { RCLCPP_ERROR(this->get_logger(), "Failed to import tracking module"); PyErr_Print(); } else { tracking_function_ = PyObject_GetAttrString(tracking_module_, "return_tracking_id"); if (!tracking_function_) { RCLCPP_ERROR(this->get_logger(), "Failed to get tracking function"); PyErr_Print(); } } [/code] Это конструктор MyNode, у меня проблемы даже за запуском