From: King on
Hi,

The 'zipimport' modules can only import (.py & .pyc) files from a zip
file and doesn't support importing .pyd & .so files. Recently I was
examining the code of Py2Exe (python package deployment tool) and I
have found that it is using a module 'zipextimporter' that can import
dlls(.pyd) modules from a zip file.
It is based on the concept of loading library form memory. You can
find out more about here:
http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/

It's strictly for windows platform. I would like to know from expert
python users and linux programmers, how we can achieve similar
functionality on linux platform? I do have limited c/c++ skill sets
but I would love to give a try.

Cheers

Prashant

From: Thomas Jollans on
On 07/09/2010 06:36 PM, King wrote:
> Hi,
>
> The 'zipimport' modules can only import (.py & .pyc) files from a zip
> file and doesn't support importing .pyd & .so files. Recently I was
> examining the code of Py2Exe (python package deployment tool) and I
> have found that it is using a module 'zipextimporter' that can import
> dlls(.pyd) modules from a zip file.
> It is based on the concept of loading library form memory. You can
> find out more about here:
> http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/
>
> It's strictly for windows platform. I would like to know from expert
> python users and linux programmers, how we can achieve similar
> functionality on linux platform? I do have limited c/c++ skill sets
> but I would love to give a try.

I don't think it's possible as such:

On UNIX systems, dynamic module loading is done with the dl* functions
in libdl. From the manual installed on my machine:


void *dlopen(const char *filename, int flag);

char *dlerror(void);

void *dlsym(void *handle, const char *symbol);

int dlclose(void *handle);

Link with -ldl.

dlopen() takes a file name. It is, as far as I know, the only, or at
least the only portable way to load a shared object.

There might be some way to load so's from memory on certain Unices, but
these would only work on one system (and I doubt they exist anyway)

So you'd have to extract the file, and make it available through the
file system. This would typically mean creating a file under /tmp (or
possibly under $HOME/.cache/...)

Cheers
Thomas


>
> Cheers
>
> Prashant
>

From: Christian Heimes on
> It's strictly for windows platform. I would like to know from expert
> python users and linux programmers, how we can achieve similar
> functionality on linux platform? I do have limited c/c++ skill sets
> but I would love to give a try.

I don't know any way to load a shared library from something other than
a file on the file system. Unless you find a variant of dlopen() that
supports memory segments, you are out of luck.

From: Thomas Jollans on
On 07/09/2010 06:36 PM, King wrote:
> Hi,
>
> The 'zipimport' modules can only import (.py & .pyc) files from a zip
> file and doesn't support importing .pyd & .so files. Recently I was
> examining the code of Py2Exe (python package deployment tool) and I
> have found that it is using a module 'zipextimporter' that can import
> dlls(.pyd) modules from a zip file.
> It is based on the concept of loading library form memory. You can
> find out more about here:
> http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/

I just had a quick look at that article (I hadn't before). It's probably
possible to do something similar on other systems: In principle, you can
know the layout of an .so, and then manually load it. But, basically,
don't. While supporting Linux itself might not be too difficult (you can
use the libdl (or kernel?) sources as a reference, I expect), but
supporting multiple UNIX variants is almost certainly very, very difficult.

Maybe there are some actual experts around with a different view, but
I'd recommend, to load object code not directly accessible via the file
system, put it in the file system!

>
> It's strictly for windows platform. I would like to know from expert
> python users and linux programmers, how we can achieve similar
> functionality on linux platform? I do have limited c/c++ skill sets
> but I would love to give a try.
>
> Cheers
>
> Prashant
>

From: King on
I think I am trying to open a can of worms. It's better to leave the
idea for now.

Prashant