Python embedding question.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Troeger

    Python embedding question.

    Hi,

    Sorry I've posted a similar question some weeks ago, but I got no
    answers. I want to embed a Python application on a device with limited
    resources, esp. storage limitations. Is there a way to reduce the Python
    interpreter to a set of modules that's urgently needed? Or is there a
    method to have gzipped modules that are unzipped on the fly into memory
    when they're accessed? That would be even better.

    Additionally, is there a Python module that contains all the stuff
    needed for an embedded application like graphics, sound etc. or do I
    have to use the various bindings to libraries like cairo, Qt or similar?
    Is there a site that helps with those decisions?

    I've really looked at a lot of places but haven't found a suitable
    solutions yet, so I'm asking here in hope that someone has experience
    with that topic.

    Regards,
    Thomas.
  • Kay Schluehr

    #2
    Re: Python embedding question.

    On 15 Jul., 11:51, Thomas Troeger <thomas.troeger ....@siemens.co m>
    wrote:
    I've really looked at a lot of places but haven't found a suitable
    solutions yet, so I'm asking here in hope that someone has experience
    with that topic.
    Which solutions did you rule out?

    Comment

    • Thomas Troeger

      #3
      Re: Python embedding question.

      Kay Schluehr wrote:
      On 15 Jul., 11:51, Thomas Troeger <thomas.troeger ....@siemens.co m>
      wrote:
      >
      >I've really looked at a lot of places but haven't found a suitable
      >solutions yet, so I'm asking here in hope that someone has experience
      >with that topic.
      >
      Which solutions did you rule out?
      - Python + Qt, because it's definitely overkill for my plans. I only
      need simple graphics and some sound, no widgets. Basically I'm looking
      for something really lightweight that has methods for drawing graphic
      primitives and renders fonts -- no complicated widgets, windows,
      scrollbars and the like. And, for example, the Qt library is a real
      heavyweight with approx. 10 MB for qt-3.3.8 alone.

      - The same holds for cairo/pango, I've written a test program (in C, I
      must say) that has dynamic links to 10 libraries that are all like 250kb
      in size. That's a lot for a small embedded device.

      I'd like a solution that's not over 10MB altogether, and the interpreter
      comes at a 60 MB if all modules are included. I can't imagine noone has
      had this problem before... and I'm trying to not invent the wheel again :^)

      Comment

      • Uwe Schmitt

        #4
        Re: Python embedding question.

        On 15 Jul., 12:14, Thomas Troeger <thomas.troeger ....@siemens.co m>
        wrote:
        Kay Schluehr wrote:
        On 15 Jul., 11:51, Thomas Troeger <thomas.troeger ....@siemens.co m>
        wrote:
        >
        I've really looked at a lot of places but haven't found a suitable
        solutions yet, so I'm asking here in hope that someone has experience
        with that topic.
        >
        Which solutions did you rule out?
        >
        - Python + Qt, because it's definitely overkill for my plans. I only
        need simple graphics and some sound, no widgets. Basically I'm looking
        for something really lightweight that has methods for drawing graphic
        primitives and renders fonts -- no complicated widgets, windows,
        scrollbars and the like. And, for example, the Qt library is a real
        heavyweight with approx. 10 MB for qt-3.3.8 alone.
        >
        - The same holds for cairo/pango, I've written a test program (in C, I
        must say) that has dynamic links to 10 libraries that are all like 250kb
        in size. That's a lot for a small embedded device.
        >
        Did you try pygame ? I think it has a small footprint.

        Greetings, Uwe

        Comment

        • David Lyon

          #5
          Re: Python embedding question.

          Thomas Troeger wrote:
          I want to embed a Python application on a device with limited
          resources, esp. storage limitations. Is there a way to reduce the
          Python interpreter to a set of modules that's urgently needed?
          Of course there is. What is the target platform ?

          What can be done is to go through the python source code and comment out
          everything that *you* find unneccessary. I can't tell you what this
          would be - because I don't know exactly what you are after. But to your
          question - the answer is yes.. of course.
          Or is there a method to have gzipped modules that are unzipped on the
          fly into memory when they're accessed? That would be even better.
          Yes - also possible.
          >
          Additionally, is there a Python module that contains all the stuff
          needed for an embedded application like graphics, sound etc.
          No. Because that depends on what hardware platform you want to run on.
          or do I have to use the various bindings to libraries like cairo, Qt
          or similar? Is there a site that helps with those decisions?
          I doubt it. These are decisions for you to make according to the
          limitations of your hardware.
          >
          I've really looked at a lot of places but haven't found a suitable
          solutions yet, so I'm asking here in hope that someone has experience
          with that topic.
          >
          :-)

          Regards

          David

          Comment

          • Troeger, Thomas (ext)

            #6
            AW: Python embedding question.

            Hi,
            I want to embed a Python application on a device with limited
            resources, esp. storage limitations. Is there a way to reduce the
            Python interpreter to a set of modules that's urgently needed?
            Of course there is. What is the target platform ?
            Thanks for your answer. The plattform is x86, so basically it's a PC
            with a compact flash drive. The problem is that the compact flash is
            rather limited in speed and size (there is other stuff on it too).
            Or is there a method to have gzipped modules that are unzipped on
            the
            fly into memory when they're accessed? That would be even better.
            Yes - also possible.
            That sounds promising, is there a link you can give? Or do I have to
            modify the module loading code for this, i.e. the interpreter? I think
            that wouldn't be too much of a problem if I understand where Python
            loads modules; I haven't checked the Python source yet for that one, and
            searching for Python and zip or similar always yields tons of links that
            use the Python zip or tar module :)
            Regards
            David
            Cheers,
            Thomas.

            Comment

            • Jerry Hill

              #7
              Re: Python embedding question.

              On Tue, Jul 15, 2008 at 5:51 AM, Thomas Troeger
              <thomas.troeger .ext@siemens.co mwrote:
              Or is there a method to have gzipped
              modules that are unzipped on the fly into memory when they're accessed? That
              would be even better.
              Yes. See the documentation for the zipimport module, and PEP 273.

              Source code: Lib/zipimport.py This module adds the ability to import Python modules (*.py,*.pyc) and packages from ZIP-format archives. It is usually not needed to use the zipimport module explicit...

              This PEP adds the ability to import Python modules *.py, *.py[co] and packages from zip archives. The same code is used to speed up normal directory imports provided os.listdir is available.


              --
              Jerry

              Comment

              • Jan Claeys

                #8
                Re: Python embedding question.

                Op Tue, 15 Jul 2008 11:51:47 +0200, schreef Thomas Troeger:
                I want to embed a Python application on a device with limited
                resources, esp. storage limitations. Is there a way to reduce the Python
                interpreter to a set of modules that's urgently needed?
                You might want to have a look at how the OpenWRT people do it.

                In general: have a look at embeded linux projects, several of them have
                python packages... ;-)

                Additionally, is there a Python module that contains all the stuff
                needed for an embedded application like graphics, sound etc. or do I
                have to use the various bindings to libraries like cairo, Qt or similar?
                I'd say that PyGame could be a solution.

                Or otherwise you could do your own audio/graphics programming (you don't
                tell us which OS you use, but there exist python modules that allow you
                to do barebones graphics & sound programming on linux...).


                --
                JanC

                Comment

                • Thomas Troeger

                  #9
                  Re: Python embedding question.

                  Jan Claeys wrote:
                  I'd say that PyGame could be a solution.
                  >
                  Or otherwise you could do your own audio/graphics programming (you don't
                  tell us which OS you use, but there exist python modules that allow you
                  to do barebones graphics & sound programming on linux...).
                  Yes, I'm using a very small Linux system with busybox, running from a
                  compact flash drive. I'll investigate PyGame, it sounds as if it is a
                  good candidate :P

                  Thanks so far,
                  Thomas.

                  Comment

                  • Thomas Troeger

                    #10
                    Re: Python embedding question (2).

                    I'd say that PyGame could be a solution.
                    >
                    Or otherwise you could do your own audio/graphics programming (you don't
                    tell us which OS you use, but there exist python modules that allow you
                    to do barebones graphics & sound programming on linux...).
                    After some more reading I've stumbled over pyglet. Any experiences with
                    it? It seems it does a lot of cool things, if anyone has used it more
                    intensely I'd be happy to hear if the following things can be done:

                    - Linux framebuffer (16, 24 bpp) display of 2d graphics with overlays
                    (i.e. menues, contextual areas that pop up etc.). I don't have X on the
                    embedded device, just the regular framebuffer.
                    - alpha blending of several layers.
                    - rendering of TTF fonts and unicode, for example display of arabic text
                    (which renders from right to left) and mixed text support like in the
                    unicode bidirectional algorithm.
                    - hardware caching of bitmaps for faster graphics operations (needed for
                    tool tips or similar tasks).

                    I'll try to find that out myself (I'm pretty excited about the thing
                    already ^^), but I'd be happy to hear of people who have used it already.

                    Cheers,
                    Thomas.

                    Comment

                    • Carl Banks

                      #11
                      Re: Python embedding question (2).

                      On Jul 17, 9:57 am, Thomas Troeger <thomas.troeger ....@siemens.co m>
                      wrote:
                      I'd say that PyGame could be a solution.
                      >
                      Or otherwise you could do your own audio/graphics programming (you don't
                      tell us which OS you use, but there exist python modules that allow you
                      to do barebones graphics & sound programming on linux...).
                      >
                      After some more reading I've stumbled over pyglet. Any experiences with
                      it? It seems it does a lot of cool things, if anyone has used it more
                      intensely I'd be happy to hear if the following things can be done:
                      >
                      - Linux framebuffer (16, 24 bpp) display of 2d graphics with overlays
                      (i.e. menues, contextual areas that pop up etc.). I don't have X on the
                      embedded device, just the regular framebuffer.
                      - alpha blending of several layers.
                      - rendering of TTF fonts and unicode, for example display of arabic text
                      (which renders from right to left) and mixed text support like in the
                      unicode bidirectional algorithm.
                      - hardware caching of bitmaps for faster graphics operations (needed for
                      tool tips or similar tasks).
                      >
                      I'll try to find that out myself (I'm pretty excited about the thing
                      already ^^), but I'd be happy to hear of people who have used it already.
                      Pyglet runs on top of OpenGL, which might have performance problems on
                      an embedded device, if OpenGL or Mesa is even supported. If it's
                      supported, I suspect performance will be adequate for 2D drawing. It
                      almost certainly is the lightest solution you can find.


                      Carl Banks

                      Comment

                      • Thomas Troeger

                        #12
                        Re: Python embedding question (2).

                        Carl Banks wrote:
                        On Jul 17, 9:57 am, Thomas Troeger <thomas.troeger ....@siemens.co m>
                        wrote:
                        >>I'd say that PyGame could be a solution.
                        >>Or otherwise you could do your own audio/graphics programming (you don't
                        >>tell us which OS you use, but there exist python modules that allow you
                        >>to do barebones graphics & sound programming on linux...).
                        Pyglet runs on top of OpenGL, which might have performance problems on
                        an embedded device, if OpenGL or Mesa is even supported. If it's
                        supported, I suspect performance will be adequate for 2D drawing. It
                        almost certainly is the lightest solution you can find.
                        >
                        >
                        Carl Banks
                        I've managed to put together a small pyGame program, it runs smoothly
                        and seems to be exactly what I wanted. It's fast! Even with 100 moving
                        objects it still runs so fast that I can consider using Python/pyGame
                        for the whole project.

                        There are still some questions left which I haven't found out by myself,
                        so maybe someone here can answer them:

                        - I can't see how to create more sophisticated text output, it seems the
                        built in font render facilities are limited to simple strings. Is that
                        true? I'd need a way to at least render multiline text with paragraphs
                        and bidirectionalit y, like pango does it. Is there a way to integrate
                        pango support into pyGame? I'd prefer marked up text display with text
                        properties ...
                        - Is there some way to reserve screen areas so they are excluded from a
                        blit, or do I have to manage stuff like this myself? I am thinking about
                        several graphic layers where each layer is painted on top of the next
                        layer, for example to draw a gui in front of a background image.
                        - There seems to be support for video overlay, i.e. is it possible to
                        have an external program paint an image from a camera into a portion of
                        the screen while pyGame is running?

                        Maybe this is the wrong list to ask, so please forgive the question but
                        direct me to somewhere better.

                        Cheers,
                        Thomas.

                        Comment

                        • Uwe Schmitt

                          #13
                          Re: Python embedding question (2).

                          On 22 Jul., 14:07, Thomas Troeger <thomas.troeger ....@siemens.co m>
                          wrote:
                          Carl Banks wrote:
                          On Jul 17, 9:57 am, Thomas Troeger <thomas.troeger ....@siemens.co m>
                          wrote:
                          >I'd say that PyGame could be a solution.
                          >Or otherwise you could do your own audio/graphics programming (you don't
                          >tell us which OS you use, but there exist python modules that allow you
                          >to do barebones graphics & sound programming on linux...).
                          Pyglet runs on top of OpenGL, which might have performance problems on
                          an embedded device, if OpenGL or Mesa is even supported.  If it's
                          supported, I suspect performance will be adequate for 2D drawing.  It
                          almost certainly is the lightest solution you can find.
                          >
                          Carl Banks
                          >
                          I've managed to put together a small pyGame program, it runs smoothly
                          and seems to be exactly what I wanted. It's fast! Even with 100 moving
                          objects it still runs so fast that I can consider using Python/pyGame
                          for the whole project.
                          >
                          There are still some questions left which I haven't found out by myself,
                          so maybe someone here can answer them:
                          >
                          - I can't see how to create more sophisticated text output, it seems the
                          built in font render facilities are limited to simple strings. Is that
                          true? I'd need a way to at least render multiline text with paragraphs
                          and bidirectionalit y, like pango does it. Is there a way to integrate
                          pango support into pyGame? I'd prefer marked up text display with text
                          properties ...
                          - Is there some way to reserve screen areas so they are excluded from a
                          blit, or do I have to manage stuff like this myself? I am thinking about
                          several graphic layers where each layer is painted on top of the next
                          layer, for example to draw a gui in front of a background image.
                          - There seems to be support for video overlay, i.e. is it possible to
                          have an external program paint an image from a camera into a portion of
                          the screen while pyGame is running?
                          >
                          Maybe this is the wrong list to ask, so please forgive the question but
                          direct me to somewhere better.
                          >
                          Cheers,
                          Thomas.
                          Maybe http://sourceforge.net/projects/pygameui/ helps you,
                          at least the source code.

                          Greetings, Uwe

                          Comment

                          • alex23

                            #14
                            Re: Python embedding question (2).

                            On Jul 22, 10:07 pm, Thomas Troeger <thomas.troeger ....@siemens.co m>
                            wrote:
                            Maybe this is the wrong list to ask, so please forgive the question but
                            direct me to somewhere better.


                            There are instructions on that page for joining the mailing list if
                            Google Groups aren't your thing.

                            Comment

                            Working...