I have this C code i took from https://docs.python.org/3/extending/embedding.html:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
int
main(int argc, char *argv[])
{
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("import numpy as np \n"
"student = np.dtype([('name','S20'), ('age', 'i1'), ('marks', 'f4')])\n"
"print(student)\n");
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(program);
return 0;
}
It compiles and runs quite nicely in a machine that has python3 and python3-numpy installed. The output:
[('name', 'S20'), ('age', 'i1'), ('marks', '<f4')]
However, if the target machine does not have numpy installed, the output is:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
My question: is it possible to run the python code from the app executable in a target machine that has no Python3 nor numpy installed? If so, how do i do it?
I mostly thinking of Win10 as a target machine, but i guess my question would equally apply to other OSes.
Thanks!
EDIT: To be more exact, I am not asking if this code can be compiled without having Python installed. I know it must have some python-dev to be compiled.
But what I want to know is there a way to create an .exe file that uses some Python calls without having Python installed in the target machine?