Following this thread
Assume I have the following files in the directory prog:
main.cpp (located in the directory prog)
int main(int argc, char *argv[]){
Py_Initialize();
//Adding current path
PyObject* sys = PyImport_ImportModule("sys");
PyObject* path = PyObject_GetAttrString(sys, "path");
PyObject* cur_dir = PyUnicode_FromString("");
PyList_Append(path, cur_dir);
PyObject* myModuleString = PyUnicode_DecodeFSDefault((char*)"multiset_bell_numbers.py");
PyObject *pModule = PyImport_Import(myModuleString);
if (pModule == nullptr) {
PyErr_Print();
throw std::runtime_error("pModule is empty");
}
return 0;
}
multiset_bell_numbers.py (located in the directory prog)
from sympy.utilities.iterables import multiset_partitions
def calc_partitions(arr):
res = list(multiset_partitions(arr))
res.sort(key=lambda part:len(part))
return res
CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(prog)
set(CMAKE_CXX_STANDARD 17)
find_package(Python REQUIRED COMPONENTS Interpreter Development)
include_directories(${Python_INCLUDE_DIRS})
add_executable(prog main.cpp)
target_link_libraries(prog ${Python_LIBRARIES})
But still got an error:
ModuleNotFoundError: No module named 'multiset_bell_numbers'
I have also tried to remove ".py" from the suffix of the string What should I do?