[capi-sig] Import

Francis Bolduc francis.bolduc at cm-labs.com
Thu Feb 28 22:14:26 CET 2013


> - I had to set path to both "lib" and to "lib/lib-dynload" - why is that?
> If I remember correctly, on Windows there used to be two directories "Lib"
> and "libs" (?) - one containing C extensions and the other one pure Python
> modules. That has changed? In any case, why do I have to point to the
> "lib-dynload" as well, why can't the interpreter recursively search the top
> most "lib"? And if I wanted to include new modules, should I put them
> inside "site-packages"?



I don't have an answer for that.



> - the docs say, "The path components should be separated by semicolons"
> that is ";" - but I had to use ":" - I'm on Mac, maybe the are the docs
> Windows specific?



Then I think the doc is wrong. I do the following:

    #ifdef _WIN32
        char separator = ';';
    #else
        char separator = ':';
    #endif



> - to enable Python to import stdlib, is it the right way to do so with
> "Py_SetPath()"?
> Or are there other idioms?



It is the right way.



> - I read somewhere sometime that it may be possible to incude giant .zip
> file, instead of all the libraries files (.py, .so) - is it true? How does
> a script import from such an archive?



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 hope you don't mind such newbie questions...



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.



-- 
Francis Bolduc, B.Sc.
CM-Labs Simulation Inc.


More information about the capi-sig mailing list