Cross-compiling Python for MIPS and ARM Platforms

Python programming language is used in several open source projects such as Sugar OS and Xibo. Let’s see if we can cross-compile it in Ubuntu 10.10 using a mips compiler.

I’ll use the instructions given at http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html.

Let’s download Python 2.7.1 first and extract the source code:


Then run the following command in Python-2.7.1 in order to build some tools for the host:


There is no patch for Python 2.7.1 cross-compilation in the link above, so let’s just try to configure and build it:


If we don’t use a patch the first error is:


So I used some older patch to create a new patch: http://www.cnx-software.com/patch/python-2.7.1-cross-compile.patch. You can download it an apply it as follows:


And repeat the step above to configure and cross-compile Python for mips.

Finally install Python in ~/Python-2.7.1/install for example:


After that copy all necessary files in ~/Python-2.7.1/install to your target board and run the python test:

Support CNX Software - Donate via PayPal or become a Patron on Patreon

23
Leave a Reply

avatar
13 Comment threads
10 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
9 Comment authors
willytkaiserliucongManikantaSteven Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
novita
Guest
novita

hi,

what should I type for ARM instead of MIPS ?

thank you

maciej walczak
Guest
maciej walczak

And how add support for dbus and glib to python running on arm ? I made this procedure and everything works just fine but I need also dbus python module, do you have any guide how to do it ?

trackback

[…] http://www.cnx-software.com/2011/02/04/cross-compiling-python-for-mips-and-arm-platforms/  又一篇移植python的文章,不过针对的是gnu库,而不是android的。 […]

sai
Guest
sai

@cnxsoft
for arm, make file created successfully without errors. But when i make by using the command
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-none-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-none-linux- CROSS_COMPILE_TARGET=yes

i got the error as

arm-none-linux-gnueabi-gcc -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c
In file included from Include/Python.h:58:0,
from ./Modules/python.c:3:
Include/pyport.h:243:13: error: #error “This platform’s pyconfig.h needs to define PY_FORMAT_LONG_LONG”
make: *** [Modules/python.o] Error 1

Help me to solve the issue..

sai
Guest
sai

It successfully created make file for arm, But while make by using the command

make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-none-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-none-linux- CROSS_COMPILE_TARGET=yes

i get the error as

arm-none-linux-gnueabi-gcc -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.7.a -lpthread -ldl -lpthread -lutil -lm
File “./setup.py”, line 316
self.announce(‘*** WARNING: renaming “%s” since importing it’
^
IndentationError: expected an indented block
make: *** [sharedmods] Error 1

Help me to solve..

sai
Guest
sai

To cross compiling Python 3.5 for arm, what the patch i have to use ? or any other process to cross compile.
Suggest me

sai
Guest
sai

cnxsoft :
@sai
Maybe it’s because of the compiler you use.

thq

Steven
Guest
Steven

Hi all,

when I’m executing this command “CC=mipsel-linux-gcc CXX=mipsel-linux-g++ AR=mipsel-linux-ar RANLIB=mipsel-linux-ranlib ./configure –host=mipsel-linux –target=mipsel-linux –prefix=/python” I’m getting the following error message:
“configure: error: invalid variable name: `–host'” Do you have any idea whats causing this?

Thank you

Manikanta
Guest
Manikanta

When i am running this command

make install HOSTPYTHON=./hostpython BLDSHARED=”arm-none-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-none-linux- CROSS_COMPILE_TARGET=yes prefix=/home/arm_install

getting the error as

/usr/bin/install -c -m 644 ./LICENSE /home/arm_install/lib/python2.7/LICENSE.txt
PYTHONPATH=/home/arm_install/lib/python2.7 \
./hostpython -Wi -tt /home/arm_install/lib/python2.7/compileall.py \
-d /home/arm_install/lib/python2.7 -f \
-x ‘bad_coding|badsyntax|site-packages|lib2to3/tests/data’ \
/home/arm_install/lib/python2.7
Traceback (most recent call last):
File “/home/arm_install/lib/python2.7/compileall.py”, line 17, in
import struct
File “/home/arm_install/lib/python2.7/struct.py”, line 1, in
from _struct import *
ImportError: /u02/python_crosscompile/Python-2.7.1/build/lib.linux-x86_64-2.7/_struct.so: wrong ELF class: ELFCLASS32
make: *** [libinstall] Error 1

what is this ? How to solve.