On Fri, Mar 1, 2013 at 6:15 PM, Dave Brotherstone <davegb(a)pobox.com> wrote:
>
>
> I'm pretty sure this "just works", you put the name of the zip file in
> sys.path, then it will internally open the zip (without extracting to a
> temp location) and search for the relevant module - I don't know much
> (read: anything) about Py_SetPath, but I'm assuming it's the same.
>
>
Yes, it seems to work but apparently all the dynamic libraries cannot be
inside the zip archive (why?).
Here's what I have done:
- first put all the files (*.py) from Python stdlib into a zip archive (I
put them straight into archive, i.e. no parent directory, like:
stdlib.zip/base64.py)
- copy all the files from "lib-dynload" to the folder where you put that
zip from previous line
- Py_SetPath() to something line "parent/stdlib.zip:parent/lib-dynload".
So basically it treats the zip file as a directory. Note, that it needs
zlib in order to look inside the zip - it is in lib-dynload however - I'm
just saying in case someone wouldn't all the dynamic libraries.
Feel free to let me know if it works for you!
On Fri, Mar 1, 2013 at 2:06 PM, ecir hana <ecir.hana(a)gmail.com> wrote:
> On Thu, Feb 28, 2013 at 10:14 PM, Francis Bolduc <
> francis.bolduc(a)cm-labs.com
> > wrote:
>
> >
> > The Python interpreter can read zip files.
> >
> > This is what I do myself. I zip the entire Python library and embed it
> > inside my application. Then I extract it at run-time in a temporary
> > directory, then I point the Python interpreter to it using Py_SetPath.
> >
>
> I thought it would be possible to do without the extracting to a temporary
> directory, i.e. doing it all in-memory...
>
>
I'm pretty sure this "just works", you put the name of the zip file in
sys.path, then it will internally open the zip (without extracting to a
temp location) and search for the relevant module - I don't know much
(read: anything) about Py_SetPath, but I'm assuming it's the same.
Dave.
On Thu, Feb 28, 2013 at 10:14 PM, Francis Bolduc <francis.bolduc(a)cm-labs.com
> wrote:
>
> The Python interpreter can read zip files.
>
> This is what I do myself. I zip the entire Python library and embed it
> inside my application. Then I extract it at run-time in a temporary
> directory, then I point the Python interpreter to it using Py_SetPath.
>
I thought it would be possible to do without the extracting to a temporary
directory, i.e. doing it all in-memory...
> Not at all.
>
> Extending and embedding and distributing Python within an application
> seems to be the most common use case. Once you know what to do, it is
> actually very simple. But it is not covered in the documentation, nor
> are there any examples. I only succeeded because I actually read the
> CPython source code.
>
> Maybe, some day, somebody will feel generous and publish an example of
> how to do that. Until then, this is the best place to ask questions.
>
Thank you!