Embedded python (use of modules) on system w/o Python installed

Gregoire Banderet banderet at nagra.com
Thu Jan 15 11:05:30 EST 2004


Hi there,

I try to run a python script from a C program.
The script uses the re (regex) module.
The resulting executable must run on a system that has no lib and
python script module, i.e no re.py

How should I write my C program (I'd like to avoid any python file
installation on target system) ?
Now it is:
--------- C prg ----------
#include <python2.2/Python.h>
#define PYTHON_SCRIPT "test.py"

int main(int argc, char * argv[])
{
  FILE *fd = fopen(PYTHON_SCRIPT, "r");
  Py_Initialize();
  PyRun_SimpleFile(fd, PYTHON_SCRIPT);
  Py_Finalize();
  return 0;
}
----------------------------


---------- test.py ----------
import re

p = re.compile('(ab)*')
print p.match('ababababab').span()
------------------------------


But when I run pytest on the target system:
# ./pytest
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "test.py", line 1, in ?
    import re
ImportError: No module named re



More information about the Python-list mailing list