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:

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK Pi 4C Plus
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
23 Comments
oldest
newest
novita
novita
12 years ago

hi,

what should I type for ARM instead of MIPS ?

thank you

maciej walczak
maciej walczak
12 years ago

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 ?

sai
sai
8 years ago


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
sai
8 years ago

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
sai
8 years ago

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
sai
8 years ago

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

thq

Steven
Steven
7 years ago

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
Manikanta
6 years ago

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.

liucong
liucong
5 years ago

ake install HOSTPYTHON=./hostpython BLDSHARED=”mipsel-linux-gcc -shared” CROSS_COMPILE=mipsel-linux- CROSS_COMPILE_TARGET=yes prefix=/home/liucong/Python-2.7.1/install Parser/pgen ./Grammar/Grammar ./Include/graminit.h ./Python/graminit.c Parser/pgen: Parser/pgen: cannot execute binary file make: [Include/graminit.h] Error 126 (ignored) Parser/pgen ./Grammar/Grammar ./Include/graminit.h ./Python/graminit.c Parser/pgen: Parser/pgen: cannot execute binary file make: [Python/graminit.c] Error 126 (ignored) /usr/bin/install -c python /home/liucong/Python-2.7.1/install/bin/python2.7 if test -f libpython2.7.a; then \ if test -n “” ; then \ /usr/bin/install -c -m 555 /home/liucong/Python-2.7.1/install/bin; \ else \ /usr/bin/install -c -m 555 libpython2.7.a /home/liucong/Python-2.7.1/install/lib/libpython2.7.a; \ if test libpython2.7.a != libpython2.7.a; then \ (cd /home/liucong/Python-2.7.1/install/lib; ln -sf libpython2.7.a libpython2.7.a) \ fi \ fi; \ else true; \ fi File “./setup.py”, line 316 self.announce(‘*** WARNING: renaming “%s”… Read more »

tkaiser
tkaiser
5 years ago

> But anyway, is it a MIPS system?

x64 running CentOS 6.

liucong
liucong
5 years ago

I want to cross compile Python for mips on x64 running centos 6, how to solve this problem or what should I do?thanks

liucong
liucong
5 years ago

today,I trying . I found this problem to occur after the command was executed.this problem stills exists make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”mipsel-linux-gcc -shared” CROSS_COMPILE=mipsel-linux- CROSS_COMPILE_TARGET=yes configure: WARNING: If you wanted to set the –build type, don’t use –host. If a cross compiler is detected then cross compile mode will be used. checking for –enable-universalsdk… no checking for –with-universal-archs… 32-bit checking MACHDEP… linux2 checking EXTRAPLATDIR… checking machine type as reported by uname -m… x86_64 checking for –without-gcc… no checking for mipsel-linux-gcc… mipsel-linux-gcc checking whether the C compiler works… yes checking for C compiler default output file name… a.out checking for suffix of… Read more »

willy
willy
5 years ago

I suspect that this “pgen” utility was built with the cross-compiler instead of being built with your local CC. I’m seeing a HOSTPGEN variable in your build command that makes me think that this utility ought to have been used instead. You should carefully review the makefile to be sure that your variables are properly named and that the resulting utility is usable.

Khadas VIM4 SBC