Hello,
I want to call the function from a python file.
By googling, it looks like I need to use the following function.
I added a "Sample.py" in the same place where the exe is stored for the c++ .
int main()
{
Py_Initialize();
// Create some Python objects that will later be assigned values.
PyObject* pName, * pModule, * pFunc, * pArgs = nullptr, * pValue;
pName = PyUnicode_FromString((char*)"Sample");
pModule = PyImport_Import(pName);
pFunc = PyObject_GetAttrString(pModule, (char*)"fun");
pValue = PyObject_CallObject(pFunc, pArgs);
}
In the "Sample.py"
import matplotlib.pyplot as plt
def fun(): x = [1,2,3]
y = [2,4,1]
plt.plot(1, 2)
And when i run the c++ code, it throws an exception at PyObject_CallObject(pFunc, pArgs); saying "v was nullptr"
I just want to know if im missing any thing in my visual studio setup
Because when i change the sample.py to just following without the #import, it works fine
def fun(): print("Hello from a function")
works fine
thanks a lot