I want to embed Python 3.3.4 in my C ++ application so that:
- The Python standard library is always taken from the zip archive along with the application executable (should not depend on any surrounding vars, etc.);
- my own custom .py modules are imported from another folder or zip archive along with the executable.
And, in fact, I did almost everything right. The only thing that still does not work is to import the standard library from the ZIP archive: it works fine as a simple directory, but whenever I try to zip it up, the initialization fails with the following error:
Fatal Python error: Py_Initialize: unable to load the file system codec
Is this possible with the latest Python? I searched a lot for it, and many sources claim that working on the correct "python33.zip" should work on the executable. However, my experiments prove the opposite. What am I missing?
Here, my test code is a minimal console application created by MS Visual Studio 2010, running on Windows XP SP3, with some comments regarding what I tried and what the results are:
#include "stdafx.h"
#include "python.h"
int _tmain(int argc, _TCHAR* argv[])
{
Py_SetPath(L"python_lib.zip;_scripts.dat");
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is',ctime(time()))\n");
PyRun_SimpleString("import hello");
Py_Finalize();
return 0;
}
source
share