Skip to content

Instantly share code, notes, and snippets.

@arekt
Last active May 15, 2020 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arekt/7f846d45fcf5283ebcdc51b318130344 to your computer and use it in GitHub Desktop.
Save arekt/7f846d45fcf5283ebcdc51b318130344 to your computer and use it in GitHub Desktop.
```
## based on: https://docs.python.org/2/extending/embedding.html
arek@qyobo:~/workspace/embeding_python$ gcc -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 main.c -lpython2.7 -o run-python
arek@qyobo:~/workspace/embeding_python$ cat main.c
#include "Python.h"
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n");
PyRun_SimpleString(argv[1]);
Py_Finalize();
return 0;
}
arek@qyobo:~/workspace/embeding_python$ ./run-python "print ctime(time())"
Fri May 15 19:14:11 2020
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment