I was trying to execute a python function in C++ but when I execute the .exe file it says
Could not find platform dependent libraries <exec_prefix>
I use
g++ RunFile.cpp -o output -L C:Python39libs -lpython3 -I C:Python39include
to compile my programm.
I use python 3.9 on windows 11
C++ code:
<code>#define PY_SSIZE_T_CLEAN
#include <python3.11Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
PyObject *name, *load_module, *func, *callFunc, *args;
Py_Initialize();
name = PyUnicode_FromString((char*)"CreateExcel");
load_module = PyImport_Import(name);
func = PyObject_GetAttrString(load_module,(char*)"writeInExcel");
args = PyTuple_Pack(4,PyUnicode_FromString((char*)"erm.xlsx"), PyUnicode_FromString((char*)"PYTHON"), 0,0);
callFunc = PyObject_CallObject(func,args);
Py_Finalize();
while(true){
cout << "";
cout << Py_GetExecPrefix();
}
return 0;
}
</code>
<code>#define PY_SSIZE_T_CLEAN
#include <python3.11Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
PyObject *name, *load_module, *func, *callFunc, *args;
Py_Initialize();
name = PyUnicode_FromString((char*)"CreateExcel");
load_module = PyImport_Import(name);
func = PyObject_GetAttrString(load_module,(char*)"writeInExcel");
args = PyTuple_Pack(4,PyUnicode_FromString((char*)"erm.xlsx"), PyUnicode_FromString((char*)"PYTHON"), 0,0);
callFunc = PyObject_CallObject(func,args);
Py_Finalize();
while(true){
cout << "";
cout << Py_GetExecPrefix();
}
return 0;
}
</code>
#define PY_SSIZE_T_CLEAN
#include <python3.11Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
PyObject *name, *load_module, *func, *callFunc, *args;
Py_Initialize();
name = PyUnicode_FromString((char*)"CreateExcel");
load_module = PyImport_Import(name);
func = PyObject_GetAttrString(load_module,(char*)"writeInExcel");
args = PyTuple_Pack(4,PyUnicode_FromString((char*)"erm.xlsx"), PyUnicode_FromString((char*)"PYTHON"), 0,0);
callFunc = PyObject_CallObject(func,args);
Py_Finalize();
while(true){
cout << "";
cout << Py_GetExecPrefix();
}
return 0;
}
Python Code :
<code>def writeInExcel( fileName : str,info = "",col = 0,row = 0, sheetName = "page"):
workbook = xlsxwriter.Workbook(fileName)
worksheet = workbook.add_worksheet(sheetName)
worksheet.write(0,0,info)
workbook.close()
writeInExcel("excel.xlsx","word",0,0)
</code>
<code>def writeInExcel( fileName : str,info = "",col = 0,row = 0, sheetName = "page"):
workbook = xlsxwriter.Workbook(fileName)
worksheet = workbook.add_worksheet(sheetName)
worksheet.write(0,0,info)
workbook.close()
writeInExcel("excel.xlsx","word",0,0)
</code>
def writeInExcel( fileName : str,info = "",col = 0,row = 0, sheetName = "page"):
workbook = xlsxwriter.Workbook(fileName)
worksheet = workbook.add_worksheet(sheetName)
worksheet.write(0,0,info)
workbook.close()
writeInExcel("excel.xlsx","word",0,0)
I tried finding what they could be with Py_GetExecPrefix()
but it only returns 0