embed python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc Schellens

    embed python

    Can somebody tell me how to handle
    this #include issue when embedding python?
    Why NOT (according to the python doc) ude
    #include <python2.3/Python.h>
    ?

    And which is the library to link if I want to
    use pyhton from my application?

    Is there a standard way to deal with that issue?

    thanks,
    marc

  • Peter Strempel

    #2
    Re: embed python

    In article <c2pi2o$17dm$2@ news.riken.go.j p>, Marc Schellens wrote:[color=blue]
    > Can somebody tell me how to handle
    > this #include issue when embedding python?[/color]

    Usually "#include "Python.h" is the right way. Then tell your compiler
    to add "python2.3" to the include list. On gcc pass "-I/usr/include/python2.3"
    or similar to the compilation step.
    [color=blue]
    > Why NOT (according to the python doc) ude
    > #include <python2.3/Python.h>
    > ?[/color]

    Well, you actually can do that, it will work just as above way. But when
    you upgrade your Python to 2.4, you need to change your sourcecode. Otherwise
    you only need to change your Makefile.

    Maybe there is another, more important reason. I don't know. :)

    [color=blue]
    > And which is the library to link if I want to
    > use pyhton from my application?[/color]

    -lpython2.3 (or -lpython23 on some systems) will find the right library,
    which is libpython2.3.so in most cases (or libpython23.so or python23.dll
    if you are on Win32).


    Peter

    Comment

    • Marc Schellens

      #3
      Re: embed python

      Thanks Peter,
      [color=blue]
      > In article <c2pi2o$17dm$2@ news.riken.go.j p>, Marc Schellens wrote:
      >[color=green]
      >>Can somebody tell me how to handle
      >>this #include issue when embedding python?[/color]
      >
      >
      > Usually "#include "Python.h" is the right way. Then tell your compiler
      > to add "python2.3" to the include list. On gcc pass "-I/usr/include/python2.3"
      > or similar to the compilation step.[color=green]
      >>Why NOT (according to the python doc) ude
      >>#include <python2.3/Python.h>
      >>?[/color]
      >
      >
      > Well, you actually can do that, it will work just as above way. But when
      > you upgrade your Python to 2.4, you need to change your sourcecode. Otherwise
      > you only need to change your Makefile.[/color]

      ok, but why everybody writes #include "Python.h" instead of
      #include <Python.h> ? The latter form is the corrcet one for
      header files wich are not part of the actual project.

      marc

      Comment

      • Peter Strempel

        #4
        Re: embed python

        In article <c311q8$1vah$1@ news.riken.go.j p>, Marc Schellens wrote:
        [color=blue][color=green]
        >> Usually "#include "Python.h" is the right way.[/color][/color]
        [color=blue]
        > ok, but why everybody writes #include "Python.h" instead of
        > #include <Python.h> ? The latter form is the corrcet one for
        > header files wich are not part of the actual project.[/color]

        Yes, you are right. Should be <Python.h>. I was sloppy in my post.
        GCC should be generous and accept "Python.h", too, but it might not
        work with all compilers.

        I checked my current project code, it has <Python.h>. I don't know what
        everyone else writes. :)

        Not exactly related to your question, but if you are doing embedding,
        have a look at Pyrex which can be misused for extremely simple embedding
        as it saves you the need to write all the C boilerplate code. This isn't
        exactly what Pyrex is made for, but is a wonderful way to save some
        time and efforts.

        Peter

        Comment

        • Erik Max Francis

          #5
          Re: embed python

          Marc Schellens wrote:
          [color=blue]
          > ok, but why everybody writes #include "Python.h" instead of
          > #include <Python.h> ? The latter form is the corrcet one for
          > header files wich are not part of the actual project.[/color]

          It's a minor point. The <...> notation is for system headers, the "..."
          notation is for non-system headers, but will fall back to searching
          system headers as well.

          If it works at all -- and you haven't chosen deliberately conflicting
          filenames -- then it doesn't matter which one you use.

          --
          __ Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
          / \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
          \__/ Sometimes we're blinded by the light / If we'd only use our eyes
          -- Oleta Adams

          Comment

          Working...