Embedding Python's library as zip file

Wojtek Mamrak tacyt1007 at gmail.com
Thu May 5 06:55:05 EDT 2011


Thanks for the reply!

> Can you import from zip files when running the Python.exe interpreter?
When I zip the folder "Lib" into Python27.zip and later rename it and
try to run the python.exe, I receive an error:
"Import error: no module named site"

> Is the zip file included in sys.path?  You might need to add this
> yourself after callying Py_Initialize().
Before renaming the "Lib" folder, the path to the python27.zip exists
in sys.path.

> Is there a top-level directory in the zip file that may be throwing
> the importer off?
I am testing all the cases so this is not the issue.

> Are you getting any sort of error message?
When I run my app, it crashes while calling Py_Initialize(). The
console closes suddenly.

Is it necessary to create zip archive using zipfile.PyZipFile?

regards


2011/5/5 Ian Kelly <ian.g.kelly at gmail.com>
>
> 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?
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list