Cross-compiling Python 3.3.1 for Beaglebone (arm-angstrom)

I think I became a little too crazy over cross compiling.  For reasons now unknown to me, I decided that I wanted Python 3 on my Beaglebone.  Having just learned how to cross-compile, I was perhaps a bit ambitious.  In the end, I believe I cross-compiled successfully, but I have issues actually running Python 3 on the BB (perhaps due to PYTHONPATH issues?).  Anyway, I’m a bit overloaded with other projects at the moment so I don’t think I can see this through.  But I figured I’d write a post showing at least how to compile.

First I found a great site on how to cross-compile.  Unfortunately, it appears offline now.  A cached page is here and the real page, which is broken, is here.  In his example he shows to cross-compile Nano and the key line is where he shows how to run configure:

./configure --host=arm-angstrom-linux-gnueabi --prefix=/home/vmplanet/gccexamples/nano/nano_out/

The host parameter tells configure to setup for arm-angstrom and the prefix parameter will be the root folder when you run make install.  This allows you to easily copy that directory to your Beaglebone for installation.

Apparently, prior to Python 3.3.1, one must patch the Python source to allow for cross-compiling.  But, new to Python 3.3.1, this is no longer the case.  You can now pass --build and --host parameters to configure (like above).  For more information on this, see the Python 3.3.1 what’s new and look at the build section.  Or, see the python checkin mailing list for the issue resolutions here and here.

The final incantation that worked for me was (I’m not sure if the CC parameter is needed): ./configure CC="arm-angstrom-linux-gnueabi-gcc" --build=x86_64-ubuntu-linux --host=arm-angstrom-linux-gnueabi --disable-ipv6 --prefix=~/beaglebone/

I was using Ubuntu and you need to change the build parameter if you have a different architecture.  The CONFIG_SITE was another hack I made.  Configure grumbled about these missing lines in the file and this was the easiest (but perhaps not the correct) way to silence its grumblings.  Essentially, I created a file in the root of the source directory with the following lines:


I then ran make and make altinstall to make sure all the Python 3.3 stuff with have the suffix 3.3.  I sftp’ed the files to the Beaglebone and exploded the tar file in the root directory of the file system, but when I run python3.3 I get the following error:

Could not find platform independent libraries <prefix> 
Could not find platform dependent libraries <exec_prefix> 
Consider setting $PYTHONHOME to [:<exec_prefix>] 
Fatal Python error: Py_Initialize: Unable to get the locale encoding 
ImportError: No module named 'encodings' 

I tried various PYTHONPATH tweaks, but none seem to do the trick.  So, I’m using Python 2.7.2 for the time being.  If you happen to successfully get Python 3.3.1 installed, I’d love to hear about it 🙂


7 thoughts on “Cross-compiling Python 3.3.1 for Beaglebone (arm-angstrom)

  1. This is really fascinating, Josh. I look forward to future posts. Please try to put them in English (or German, if you prefer).

  2. Thanks for your work.
    I got it to work with some changes. Here ist what i’ve done:

    export TOOL_PREFIX=path/to/your/cross/compiler
    export CXX=$TOOL_PREFIX-g++
    export CPP="$TOOL_PREFIX-g++ -E"
    export AR=$TOOL_PREFIX-ar
    export RANLIB=$TOOL_PREFIX-ranlib
    export CC=$TOOL_PREFIX-gcc
    export LD=$TOOL_PREFIX-ld
    export READELF=$TOOL_PREFIX-readelf

    export CCFLAGS="-march=armv6 -mfpu=vfp -mfloat-abi=softfp" #you maybe have to change the flags

    echo ac_cv_file__dev_ptmx=no > ./
    echo ac_cv_file__dev_ptc=no >> ./

    ./configure --host=arm-fsl-linux-gnueabi --prefix=/opt/python3.3.1 --build=x86_64-ubuntu-linux --disable-ipv6


    This worked only on an i686-debian-linux cause my toolchain doesn’t want to work under x64 Ubuntu.

  3. Have you tried running opencv through python yet.
    I’ve got usr/include/opencv in the pythonpath yet keep getting module errors. C++ efforts find opencv fine.

    1. Unfortunately no. However, the #beagle IRC chat room on freenode and the BeagleBone mailing lists are great resources and you’d probably get an answer there.

Comments are closed.