Is it possible to embed python without a standard library?
I am working with cmake build for python 2.7.6 and I have a basic built-in script run like
#include <stdio.h> #include <Python.h> int main(int argc, char *argv[]) { /* Setup */ Py_SetProgramName(argv[0]); Py_Initialize(); /* Run the 'main' module */ int rtn = Py_Main(argc, _argv); Py_Finalize(); return rtn; }
.. but when I run it, I get:
ImportError: No module named site
If I set up the correct $ PYTHONHOME, it works fine; but that’s not what I'm trying to do. I am trying to embed a copy of python in a standalone application without a standard library.
I appreciate its use, but for this particular embedded environment, I want something more like lua (but with python syntax obviously) where only specific libraries provided by the parent application are available.
This has the added bonus of not having to worry about distributing (or creating) a standard library with all its cross dynamic libraries.
Is this possible like everyone else? Or am I inevitably about to stumble over missing fundamental blocks of the language, such as sys.path, import, {}, [] or the like, which are part of the standard library?
If possible, how would you do it?
python python-embedding
Doug Jan 06 '14 at 2:02 on 2014-01-06 14:02
source share