[capi-sig] Embedding basics

Henrique typoon at gmail.com
Thu Jun 28 14:27:25 CEST 2012

Hey Ecir,

By reading your email, I think you might want to first learn some basic
concepts about C programming and how a program can be linked to dynamic or
static libraries.
When Python is compiled in your machine, a dynamic or a static (or both)
library built, which you use to link with your program (your test.c). If
MacOS provides binaries for Python, I believe the libraries might alreayd
be there, and you might not need to compile it manually. (based on what you
are saying, you are only trying to compile it because you thought that is
how it should be done to have your test.c file to work). If you are still
interested in compiling it yourself, I believe there should be instructions
with the source (perhaps an INSTALL file there, explaining it). I am not
sure as I do not currently have the source here with me (but it should be
as simple as running ./configure && make && make install).
After you have Python compiled and running on your machine, you will write
source that will use the functions provided by the Python library in your
application, that is where your 'test.c' program comes into play.

Some time ago I wrote some introduction blog posts about the Python C API.
If you are interested, this might help you a little bit

But again, I really think you should look up some basics on C development
in a Unix platform :)



On Thu, Jun 28, 2012 at 6:08 AM, ecir hana <ecir.hana at gmail.com> wrote:

> Hello,
> please, I have a bit of trouble grasping a few very basic concepts related
> to Python embedding, could someone explain those to me?
> What I try to achieve is to have single one (big) binary, which contains my
> Python script, the wrapper and Python interpreter itself, I'm on MacOS
> 10.6. My questions are:
> - I would like to build Python myself. I downloaded Python 3.3 beta source
> code, extracted it in a folder. Next to "Python-3.3.0b1" folder, there is a
> file "test.c" which contains:
> #include <Python.h>
> int
> main(int argc, char *argv[])
> {
>  Py_Initialize();
>  PyRun_SimpleString("from time import time,ctime\n"
>                     "print('Today is', ctime(time()))\n");
>  Py_Finalize();
>  return 0;
> }
> Now, what should I do next? I though I would just "somehow" compile and
> link Python source code with test.c and that's it but when I do "gcc -I
> ./Python-3.3.0b1 -o test test.c" I get lots of errors. (Note: I'm total
> noob what this whole gcc and static linking and .a files goes...)
> - Next I tried to run "./configure" and "make". It finished without errors
> and it creates "build/lib.macosx-10.6-x86_64-3.3" folder with lots of *.so
> (?) files but I'm not sure how to make use of them.
> If building everything from scratch (the first step above) is not an
> option, what do I need to build? A "framework"? .dylib? .a? And than link
> test.o against that?
> - How does Python from python.org get build? Do they use the same
> "./configure" and "make" as I can? Do they use any special option?
> To summarize, I have Python source code and test.c and I would like to have
> one executable which says "Today is ....". Could someone, please, explain
> in layman terms, the necessary steps?
> Thanks you very much in advance!
> Ecir Hana
> _______________________________________________
> capi-sig mailing list
> capi-sig at python.org
> http://mail.python.org/mailman/listinfo/capi-sig

More information about the capi-sig mailing list