2

I have spent a good part of my day trying to run a Python file from c++. I have tried:

. . .
FILE * file = fopen ("file.py", "r");
PyRun_SimpleFile (file, "file.py");
. . . 

This however just causes my application to crash. I am using python version 3.4.

asked Nov 4, 2014 at 21:30

1 Answer 1

4

Try

Py_Initialize();
 PyRun_SimpleFile (file, "file.py");
Py_Finalize();
answered Nov 4, 2014 at 21:32
Sign up to request clarification or add additional context in comments.

4 Comments

Also possibly dumb, but make sure that you're doing #include <Python.h>
Now if I run the code it says File "file.py", line 1 ufffd/ufffd/ufffd/etc.
Well it is loading the python file but I'm getting that weird error
Perhaps post the code that prints, or the contents of the python file.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.