By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,837 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,837 IT Pros & Developers. It's quick & easy.

Python embedding question.

P: n/a
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.
Jul 15 '08 #1
Share this Question
Share on Google+
13 Replies


P: n/a
On 15 Jul., 11:51, Thomas Troeger <thomas.troeger....@siemens.com>
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?
Jul 15 '08 #2

P: n/a
Kay Schluehr wrote:
On 15 Jul., 11:51, Thomas Troeger <thomas.troeger....@siemens.com>
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 :^)
Jul 15 '08 #3

P: n/a
On 15 Jul., 12:14, Thomas Troeger <thomas.troeger....@siemens.com>
wrote:
Kay Schluehr wrote:
On 15 Jul., 11:51, Thomas Troeger <thomas.troeger....@siemens.com>
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

Jul 15 '08 #4

P: n/a
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
Jul 15 '08 #5

P: n/a
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.
Jul 15 '08 #6

P: n/a
On Tue, Jul 15, 2008 at 5:51 AM, Thomas Troeger
<th****************@siemens.comwrote:
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.

http://docs.python.org/lib/module-zipimport.html
http://www.python.org/dev/peps/pep-0273/

--
Jerry
Jul 15 '08 #7

P: n/a
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
Jul 15 '08 #8

P: n/a
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.
Jul 17 '08 #9

P: n/a
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.
Jul 17 '08 #10

P: n/a
On Jul 17, 9:57*am, Thomas Troeger <thomas.troeger....@siemens.com>
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
Jul 17 '08 #11

P: n/a
Carl Banks wrote:
On Jul 17, 9:57 am, Thomas Troeger <thomas.troeger....@siemens.com>
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 bidirectionality, 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.
Jul 22 '08 #12

P: n/a
On 22 Jul., 14:07, Thomas Troeger <thomas.troeger....@siemens.com>
wrote:
Carl Banks wrote:
On Jul 17, 9:57 am, Thomas Troeger <thomas.troeger....@siemens.com>
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 bidirectionality, 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
Jul 22 '08 #13

P: n/a
On Jul 22, 10:07*pm, Thomas Troeger <thomas.troeger....@siemens.com>
wrote:
Maybe this is the wrong list to ask, so please forgive the question but
direct me to somewhere better.
http://groups.google.com/group/pygam...-google-groups

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

This discussion thread is closed

Replies have been disabled for this discussion.