Embedding Python's library as zip file

Ian Kelly ian.g.kelly at gmail.com
Wed May 4 18:01:39 EDT 2011


On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak <tacyt1007 at gmail.com> wrote:
> Hello,
>
> I spent a lot of time googling for a solution of this problem, with no
> result.
>
> I have a C++ application, in which I would like to embed Python interpreter.
> I don't want to rely on an interpreter being installed on user machine,
> instead I would like to distribute all the necessary files with my app.
>
> As far as I understand, beside of my executable and Python.dll (I am using
> Python27), I need to provide two folders:
>  - DLLs,
>  - Lib
>
> If I place the Lib folder and the contents of the DLLs folder in a directory
> of my executable, then everything seems to work.
> However I would like to use a zipped Lib folder. Hence I made an archive
> (which contains contents of Lib folder) called Python27.zip. Unfortunately
> the app crashes during execution.
> I assume the reason might be lack of zlib.pyd. Is that assumption correct?
> If so, how to obtain it? If not, what am I doing wrong?

I believe zlib.pyd is statically linked into python27.dll nowadays.
Some things to check:

Can you import from zip files when running the Python.exe interpreter?
Is the zip file included in sys.path?  You might need to add this
yourself after callying Py_Initialize().
Is there a top-level directory in the zip file that may be throwing
the importer off?
Are you getting any sort of error message?



More information about the Python-list mailing list