Posts

Showing posts from June, 2011

Compiling Python: Modules/Setup

A little hint for Python developers who use it for embedded or unconventional platforms (like Cray supercomputers if you're lucky): it can be compiled and used without any dynamic libraries. I've got the problem with stripped libc.so - some Python shared object (like _socket.so) try to use it, but can't find anything because it's stripped. The only choice I had is using Python without these shared objects.

Fortunately, Python support it out of the box. After configuring it, you can use Modules/Setup file to set up which modules have to be compiled within the Python binary:
The build process works like this:
 1. Build all modules that are declared as static in Modules/Setup,
    combine them into libpythonxy.a, combine that into python.
 2. Build all modules that are listed as shared in Modules/Setup.
 3. Invoke setup.py. That builds all modules that
    a) are not builtin, and
    b) are not listed in Modules/Setup, and
    c) can be build on the target
For example, if you wa…

Embedding Python

Just want to share some useful links about embedding Python to your C-based application:
the main article: Embedding Python in Another Applicationadditional article that shows peculiarities of multithreading, sockets and shared memory: Embedding Python in C/C++ (Part1, Part2)Cython (or Pyrex) can be used to reduce handwritten code for Python interoperability: A quick Cython introduction If you have doubts about Python size, there are some minimal implementations: see Embedded Python article. Let me quote tinypy:
tinypy is a minimalist implementation of python in 64k of code
...
What more could you possibly want??
a pony? However, I highly recommend to use classic CPython implementation (basically because it has a huge number of contributors and supporters, and has an excellent documentation). It can be stripped up to 1-2 megabytes depending of your requirements.