Skip to content
 

Cross Compiling Python for Embedded Linux

This article details how to cross compile Python for the ARM and PowerPC platforms.  It should apply equally to other platforms as well, just plug-in the correct cross-compiler.  The article supports Python versions, 2.6.6 (Thanks to evadeflow), 2.7.2, 2.7.3 (thanks to Lothsahn) and 3.1.1, 3.1.2, 3.1.3, 3.2.2.  For version 2.7.5, please refer to Trevor Bowen’s page.

This page has been translated into http://www.webhostinghub.com/support/es/misc/cruzada-para-linux“>Spanish</a> language by Maria Ramos  from <a href=”http://www.webhostinghub.com/support/edu>Webhostinghub.com/support/edu</a>.

Firstly, download the Python that you want to use from http://www.python.org/

Unpack the Python package using tar:

tar -xvzf Python-2.7.2.tgz

This will create a directory called Python-2.7.2.  Goto the directory:

cd Python-2.7.2

Then run these commands to build the host components:

./configure

make python Parser/pgen

mv python hostpython

mv Parser/pgen Parser/hostpgen

make distclean

Download the correct patch for your version of Python:

Then apply the patch:

patch -p1 < Python-2.7.2-xcompile.patch

Then run this (where ~/Python-2.7.2/_install/ is your desired installation path).  Note also that you must replace all instances of the cross compiler and the host build system in the lines below.  If you are on an x86_64 machine, then you should use x86_64-linux-gnu as the host.

CC=ppc_6xx-gcc CXX=ppc_6xx-g++ AR=ppc_6xx-ar RANLIB=ppc_6xx-ranlib ./configure --host=ppc-linux --build=x86_64-linux-gnu --prefix=/python

make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="ppc_6xx-gcc -shared" CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes HOSTARCH=ppc-linux BUILDARCH=x86_64-linux-gnu

make install HOSTPYTHON=./hostpython BLDSHARED="ppc_6xx-gcc -shared" CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.7.2/_install

This will install all your python binaries and libraries in ~/Python-2.7.2/_install.

Copy the entire _install directory to the device, setup the PATH environment variable to include the path the Python executable and run:

python lib/python-2.7/test/test___all__.py

…and hopefully all the tests will run correctly.

To speed up the importing of Python modules on the target, I recommend to zip up the lib directory to make a file called python27.zip.  This means that we do not have to copy all the Python files to the target, just the one zip file.  This technique might also save space, but that depends on your file system.  On the host machine:

cd _install/lib/python2.7

zip -r -y python27.zip .

Delete libpythonxxx.a site-packages, lib-dynload, config and anything else you do not need from the python27.zip file.

Copy the _install/bin/python to the /usr/bin directory on the target:

Copy the python27.zip file to the /usr/lib directory on the target:

Create a directory on the target called python2.7 in the /usr/lib directory and copy the following directories to that directory:

  • ./lib/python2.7/config
  • ./lib/python2.7/lib-dynload
  • ./lib/python2.7/site-packages

Your directory structure on the target must be as follows:

/usr/lib # ls

python2.7 python27.zip

/python/lib/python2.7 # ls

config lib-dynload site-packages

Set the PYTHONHOME environment variable to /usr/ and you are ready to run Python on the target.

 

Building SQLLite and other dependancies

Thanks to Lothsahn’s 2.7.3 patch, it is now possible to build sqlite3, bz2, gz, ssl and ctypes.  Lothsahn provides the following instructions:

To do the compilation, the dependencies must be in the include and lib folder one path up from the python install.   For example:

<base directory>/include <– header files go here

<base directory>/lib <– shared object files go here

/Python-2.7.3 <—Python sources go here during compile

Dependencies include libffi, sqlite, openssl, bzip2, zlib, etc.

 

Credits

The above patches are based on Chris Lambacher’s patches for Python 2.5 here:

http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/

Other links and credits:

http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html

247 Comments

  1. KyleL says:

    Thanks for this writeup. I’m trying to get Python2.7.3 working with ctypes on MIPS. However I seem to be facing a problem where the ctypes module fails to configure:

    checking build system type… Invalid configuration `None': machine `None’ not recognized
    configure: error: /bin/sh /home/phase6/xc_python/Python-2.7.3/Modules/_ctypes/libffi/config.sub None failed
    Failed to configure _ctypes module

    Any ideas?

    Thanks,
    Kyle

    • Constantine says:

      config.sub does not recognize your architecture.
      Check that your HOSTARCH is correct you should have something like that: mipsel-unknown-linux-gnu

    • Rares says:

      I also had this problem.
      Were you able to sort it out?

    • nikhil says:

      I’m also facing this problem. Is there a solution that you are aware of ??

      • KyleL says:

        Yes I was able to build correctly using the following:

        CC=mipsel-linux-gcc CXX=mipsel-linux-g++ AR=mipsel-linux-ar RANLIB=mipsel-linux-ranlib ./configure –host=mipsel-unknown-linux-gnu –build=i686-pc-linux-gnu –prefix=/python

        make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”mipsel-linux-gcc -shared” CROSS_COMPILE=mipsel-linux- CROSS_COMPILE_TARGET=yes HOSTARCH=mipsel-linux BUILDARCH=i686-linux-gnu

        make install HOSTPYTHON=./hostpython BLDSHARED=”mipsel-linux-gcc -shared” CROSS_COMPILE=mipsel-linux- CROSS_COMPILE_TARGET=yes prefix=~/workdisk/phase6/xc_python/_install

        • nikhil says:

          thanks for the quick reply !

        • nikhil says:

          Hi ,

          I tried with the HOSTARCH and BUILDARCH option as well. I think the problem is that libffi has not been ported to cavium.

          make -C Python-2.7.2 HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”mips64-octeon-linux-gnu-gcc -shared” CROSS_COMPILE=mips64-octeon-linux-gnu- CROSS_COMPILE_TARGET=yes HOSTARCH=mips64 BUILDARCH=x86_64-linux-gnu

          checking for sys/mman.h… (cached) yes

          checking for mmap… (cached) yes

          checking whether read-only mmap of a plain file works… yes

          checking whether mmap from /dev/zero works… yes

          checking for MAP_ANON(YMOUS)… yes

          checking whether mmap with MAP_ANON(YMOUS) works… yes

          configure: error: “libffi has not been ported to mips64-unknown-elf.”

          Failed to configure _ctypes module

          Is there anything I could try that might solve this

        • nikhil says:

          Hi Kyle,

          What exact configuration did you build on? It seems that there is no ctypes support on cavium. Is that correct ? Thats what the folks at Cavium say.

          This is the error we’re seeing right now ..

          This is what I see while cross compiling. However the compilation still succeeds. Not entirely sure how to fix it.

          /home/sciadmin/workspace/cavium_new_vm/target/cavium/SDK/2.3/linux/embedded_rootfs/build/Python-2.7.2/Modules/_cursesmodule.c:2408: error: expected expression before ‘->’ token

          checking build system type… Invalid configuration `None': machine `None’ not recognized

          configure: error: /bin/sh /home/sciadmin/workspace/cavium_new_vm/target/cavium/SDK/2.3/linux/embedded_rootfs/build/Python-2.7.2/Modules/_ctypes/libffi/config.sub None failed

          Failed to configure _ctypes module

          I’d really appreciate it if you could help us figure this one out. Hope to hear from you soon!
          -Nikhil.

          • KyleL says:

            For the error: checking build system type… Invalid configuration `None’: machine `None’ not recognized

            You can refer to Constantine’s comment:
            “config.sub does not recognize your architecture.
            Check that your HOSTARCH is correct you should have something like that: mipsel-unknown-linux-gnu”

            I’m not familiar with Cavium. I am building for a Broadcom Set Top Box SoC.

            Give me your skype id if you’d like to discuss this in a easier medium

  2. Abhishek says:

    I want to cross-compile Python for a embedded system. The target is a PPC but DOES NOT run linux. Instead it runs a lesser known though capable embedded OS and I was wondering if you have attempted porting Python to a non-linux platform before.

    I have the cross compilation tool chain installed on a linux machine so I can run the configure script pointing to the target OS headers and libraries.

    Do you think this porting would be possible?

  3. Myles Dear says:

    Thanks for the instructions. They got me 90% of the way there for my Python 2.7.3 cross-compilation onto a PPC 85xx Wind River Linux 3.0 system.

    One small problem : my toolchain requires both CPPFLAGS and LDFLAGS to be set.

    In my top-level Makefile, I had to temporarily move the target’s “Makefile” and “pyconfig.h” to the host Python’s installation directory since the hostpython’s sysconfig module builds an environment variable database from these files, and these variables are used by setup.py to set CPPFLAGS and LDFLAGS to compile the Python extensions.

    I’m sure there is a more elegant solution, but this did the trick and I’m trying hard not to do any more patches than necessary to the Python distribution beyond what has been already published.

  4. Jean-Philippe Halimi says:

    Thanks for the instructions ! I’ve used them in order to cross-compile Python for Xeon Phi. I have made a repository which features the patch (https://github.com/jphalimi/PythonForMIC). Is there any problem for you ? Do you have any particular license for these files ?

  5. Vincent says:

    First, thanks for your infomation. When I compile python 2.7.3 for mips-platform, using Python-2.7.3-xcompile.patch ( Thanks to Lothsahn), I meet with such problems(after make command):
    Python build finished, but the necessary bits to build these modules were not found:
    _bsddb _curses _curses_panel
    _sqlite3 _ssl _tkinter
    bsddb185 bz2 dbm
    dl gdbm nis
    readline sunaudiodev zlib
    To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
    My host system is Ubuntu 10.04 32 bit, and cross-compiler is mips-wrs-linux-gnu-mips_74k_softfp-glibc_small-xxx,
    I tried install some libs: libreadline-dev libreadline6 libssl-dev, libbz2-dev, libgdbm-dev, libreadline5-dev? libsqlite3-dev and so on, but nothing different. I don’t understand why.
    My parameters:
    CC=mips-wrs-linux-gnu-mips_74k_softfp-glibc_small-gcc CXX=mips-wrs-linux-gnu-mips_74k_softfp-glibc_small-g++ AR=mips-wrs-linux-gnu-mips_74k_softfp-glibc_small-ar RANLIB=mips-wrs-linux-gnu-mips_74k_softfp-glibc_small-ranlib ./configure –host=mips-linux –build=i686-linux-gnu –prefix=/python

    make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”mips-wrs-linux-gnu-mips_74k_softfp-glibc_small-gcc -shared” CROSS_COMPILE=mips-wrs-linux-gnu-mips_74k_softfp-glibc_small- CROSS_COMPILE_TARGET=yes HOSTARCH=mips-linux BUILDARCH=i686-linux-gnu

    • Paul Gibson says:

      Hi Vincent,

      Your build has succeeded, those modules are optional. Do you really need these modules? You cannot fix them by installing host dev packages, you actually need to cross-compile them separately using the setup.py scripts which is an advanced task. There should be a post somewhere on this page that shows instructions for sqlite3.

      If you need the other modules, I recommend you skip this page and use buildroot.

      Paul

      • Vincent says:

        Thanks to Paul Gibson, that is very useful!

      • Vincent says:

        Hi Paul Gibson,
        I have some good news! What I really need is zlib and readline modules, there is a way to build them correctly.
        I have printed some parameters in setup.py, e.g. do_readline = self.compiler.find_library_file(lib_dirs, ‘readline’), and do_readline is None.
        I knew the readline library was localed in /usr/lib, by running command:
        dpkg -L libreadline6-dev

        /usr/lib/libreadline.a

        So, I modified the line to this:
        do_readline = self.compiler.find_library_file(lib_dirs+[‘/usr/lib’], ‘readline’)
        and make clean, remake it. It works, _curses.so and readline.so appeared in lib/python2.7/lib-dynload floder.
        This method is available to zlib too.
        Now, readline and zlib are both work on my mips-platform!

  6. Sam Jones says:

    Hi Paul,

    I was wondering if you could help me out here. First of all though, thanks for the great work here. I came across these instructions via a script I found while googling: https://github.com/wewei/Build-Python-for-iOS

    I have the libpython2.7.a in my XCode iOS app, but upon Py_Initialize(); I get these errors (with PYTHONVERBOSE=1):

    loadPyFile: 1
    # installing zipimport hook
    import zipimport # builtin
    # installed zipimport hook
    ImportError: No module named site
    # clear __builtin__._
    # clear sys.path
    # clear sys.argv
    # clear sys.ps1
    # clear sys.ps2
    # clear sys.exitfunc
    # clear sys.exc_type
    # clear sys.exc_value
    # clear sys.exc_traceback
    # clear sys.last_type
    # clear sys.last_value
    # clear sys.last_traceback
    # clear sys.path_hooks
    # clear sys.path_importer_cache
    # clear sys.meta_path
    # clear sys.flags
    # clear sys.float_info
    # restore sys.stdin
    # restore sys.stdout
    # restore sys.stderr
    # cleanup __main__
    # cleanup[1] zipimport
    # cleanup[1] signal
    # cleanup[1] exceptions
    # cleanup[1] _warnings
    # cleanup sys
    # cleanup __builtin__
    # cleanup ints: 5 unfreed ints
    # cleanup floats

    The point at which it crashes is, “ImportError: No module named site”. Am I correct in thinking that shared modules are compiled with the static library rather than being .dylib (disallowed on iOS as far as I know). If so, why can my interpreter not find the modules?!

    I’m really at a loss here. Any help would be greatly appreciated. Thanks in advance

    • Paul Gibson says:

      Hi Sam,

      I’m not an iOS expert, but on Linux this normally means that your PYTHONHOME variable is not set or incorrect. I’m not sure the exact format you should use on iOS, but google should help if you search for your error message and PYTHONHOME.

      Good luck!
      Paul

    • I am having the exact same error on a Arm linux system when running python. I cross compiled it with poky tool chain.
      I have setup PYTHONHOME to point to the python2.7/lib where site.py is

      “ImportError: No module named site”.

      Has anybody faced a similar problem?

  7. Carl says:

    Hi,

    First, thanks for the tutorial. I cross-compiled python 2.7.3, and using the “file” command on the python2.7 executable, I get: “ELF 32-bit MSB executable, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped”.

    However, I get an error when I dump it on the target and try to execute it. It says:

    ~# python
    /bin/python: line 1: syntax error: unexpected “(”

    Any idea why it does that? I would expect to get the python interactive prompt.

  8. Chris Rolls says:

    Hi paul:

    Do you know if this method will work for a Embedded computer running linux2.6.9 which needs the arm-linux-gcc cross compiler.
    Im trying to get python3.2.3 onto the EC so i can run some python code.

    If i just want to run python code on the EC do i need python installed?

    I have tried cx_freeze but this did not work. |It could not read the binary file.

    Sorry im new to linux :(

    Thanks chris

    • Paul Gibson says:

      Hi Chris,

      Yes, this method should work on Linux 2.6.9 if you have the correct cross compiler.

      I googled your question about python installation and got the following answer:
      http://stackoverflow.com/questions/5539736/python-can-i-run-a-python-script-without-actually-installing-python

      cx_freeze should work, but you need to make sure its generating binaries for arm. If it generates x86 binaries, then it will not run.

      Paul

      • Chris Rolls says:

        cheers for the reply paul. Could i be annoying and ask you to explain what you mean by creating the correct binaries and how to check? or maybe give me a direction for things i neeed to learn?

        Thanks in advance

        • Paul Gibson says:

          Hi Chris,

          If you are using cx_freeze on your desktop PC, then it is probably creating a binary that will run on the PC (eg x86 or x86_64 architecture). The ARM architecture is different and will not run x86/x86_64 binaries.

          You can check if the binary is ARM compatible by running the readelf command:
          $ readelf -A program

          Attribute Section: aeabi
          File Attributes
          Tag_CPU_name: “7-A”
          Tag_CPU_arch: v7
          Tag_CPU_arch_profile: Application
          Tag_ARM_ISA_use: Yes
          Tag_THUMB_ISA_use: Thumb-2
          Tag_FP_arch: VFPv3
          Tag_Advanced_SIMD_arch: NEONv1
          Tag_ABI_PCS_wchar_t: 4
          Tag_ABI_FP_rounding: Needed
          Tag_ABI_FP_denormal: Needed
          Tag_ABI_FP_exceptions: Needed
          Tag_ABI_FP_number_model: IEEE 754
          Tag_ABI_align_needed: 8-byte
          Tag_ABI_align_preserved: 8-byte, except leaf SP
          Tag_ABI_enum_size: int
          Tag_ABI_HardFP_use: SP and DP
          Tag_ABI_VFP_args: VFP registers
          Tag_CPU_unaligned_access: v6
          Tag_Virtualization_use: TrustZone

          Paul

    • Lothsahn says:

      Chris:

      2.6.9 is very very old. I was not able to get this to compile correctly on a device running 2.6.8 because the toolchain was very old and not compliant with some C standards. Consider yourself warned.

      You will likely be able to get it to compile (I did), but make sure you run the Python testcases. They were the ones that warned me that Python was very very broken. It was a direct result of the kernel age and toolchain problems.

  9. Dustin Gooding says:

    Thanks for the post Paul. Very helpful.

    I’m attempting to build the bz2 dependency and am running into a problem. Perhaps you could give some advice?

    I’m running Ubuntu 12.04 64, and building for an ARM Linux target. I’ve got a copy of my sysroot at ~/digi-sysroot, and I’ve copied my cross-compiled bz2 headers/libraries into ~/digi-sysroot/include and ~/digi-sysroot/lib respectively. I’ve unzipped Python 2.7.3 sources into ~/digi-sysroot as well (based on the pathing described in your “building dependencies” section), built the host tools, and patched. Then I execute the following

    /**
    ~/digi-sysroot/Python-2.7.3$ CC=arm-cortex_a8-linux-gnueabi-gcc CXX=arm-cortex_a8-linux-gnueabi-g++ AR=arm-cortex_a8-linux-gnueabi-ar RANLIB=arm-cortex_a8-linux-gnueabi-ranlib ./configure –host=arm-cortex_a8-linux-gnueabi –build=arm-linux –prefix=/python

    ~/digi-sysroot/Python-2.7.3$ make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-cortex_a8-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-cortex_a8-linux-gnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-cortex_a8-linux-gnueabi BUILDARCH=arm-linux
    … snip …
    Python build finished, but the necessary bits to build these modules were not found:
    _bsddb _curses _curses_panel
    _sqlite3 _ssl _tkinter
    bsddb185 bz2 dbm
    dl gdbm imageop
    nis readline sunaudiodev
    zlib
    To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
    **/

    The make command still fails to find dependencies (specifically bz2). But I know its there:

    /**
    ~/digi-sysroot$ ls include/bzlib.h
    include/bzlib.h

    ~/digi-sysroot$ file lib/libbz2.*
    lib/libbz2.a: current ar archive
    lib/libbz2.so.1.0: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
    lib/libbz2.so.1.0.6: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
    **/

    I feel like there should be some way of telling configure/make about my sysroot path. Any advice?

    • Dustin Gooding says:

      Sorry to reply to my own question, but I made a breakthrough. I added “PYTHON_XCOMPILE_DEPENDENCIES_PREFIX=~/digi-sysroot” to my “make” arguments and the bz2 module was found and built.

      /**
      ~/digi_sysroot/Python-2.7.3/_install$ file ./lib/python2.7/lib-dynload/bz2.so
      ./lib/python2.7/lib-dynload/bz2.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
      **/

      Might mention that variable in your instructions. I don’t know that the path of Python-x.y.z relative to your sysroot is important if you can just define the sysroot variable directly.

  10. Dawood says:

    Dear Paul
    Thanks for your great tutorial. I used it to cross-compile Python-2.7.2 for Advantech ROM-1210 (ARM) board and it has been installed. Now, I need to install Numpy-1.5 (as a python module), but I couldn’t find any apt instruction to cross-compile this module! Could you please introduce me a reference to cross-compile Python-2.7.2 with Numpy module?
    Thanks in advance.
    Regards,
    Dawoood

  11. Leo says:

    Hi Paul,

    Im a bit of a noob at this as its the first time ive tried compiling anything.

    Ive got to the point after applying the patch, where the actual compile happens, and very confused. Im trying to compile Python for android arm, i know that Android provides toolchains and an NDK, but i have no idea how to use them or plug them in to the above commands.
    My host machine is an ubuntu 12.04LTS, and my target is an Android Nexus 7 running 4.3. (although im hoping to be able to run the compile on other versions of android as its for a rooted app im currently making).

    Any help would be greatly appreciated.

    Thanks, Leo.

  12. xi says:

    Hi Paul.

    I want to know if I want to compile for ARM. What I should write about the following command
    CC=ppc_6xx-gcc CXX=ppc_6xx-g++ AR=ppc_6xx-ar RANLIB=ppc_6xx-ranlib ./configure –host=ppc-linux –build=x86_64-linux-gnu –prefix=/python
    make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”ppc_6xx-gcc -shared” CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes HOSTARCH=ppc-linux BUILDARCH=x86_64-linux-gnu
    make install HOSTPYTHON=./hostpython BLDSHARED=”ppc_6xx-gcc -shared” CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.7.2/_install
    My host machine is common Ubuntu system. What’s the mean about –host and –build.

    Thanks.

    • Paul Gibson says:

      Hi Xi,

      You need to replace ppc_6xx- with the name of your ARM toolchain. For example, if your toolchain name is arm-linux-gnueabi then you would replace ppc_6xx-gcc with arm-linux-gnueabi-gcc.
      Host should be arm-linux
      Build is the tuple of your build machine, either x86_64-linux-gnu or the 32-bit i686 equivalent.

      Paul

  13. PJM says:

    Great info!

    So I want to cross compile and install a package (http://pythonhosted.org/evdev/) on my target. How do I do that? I can download the package and run:

    $ hostpython setup.py build -x bdist_egg –plat-name=arm-linux-gnueabi

    Then theoretically I can move the egg and run easy_install on the target once Python is up and running on that machine.
    I’ve got Python to compile on the dev system and have it located in ~/Python2.7.3/_install as described above.
    Apparently I’ve got to point PYTHONPATH to (and install) setuptools and distutils somewhere. Am I doing this right? Any hints would be useful/ helpful.

    Thanks in advance.

  14. xite says:

    Hi,

    i tried to cross compile Python 3.4.1 on Ubuntu 14.04:
    I did the following steps:
    ./configure
    make python Parser/pgen
    mv python hostpython
    mv Parser/pgen Parser/hostpgen
    make distclean

    ./configure –disable-ipv6 –build=x86_64-linux-gnu –host=arm-linux-gnueabi –prefix=/python CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ CONFIG_SITE=config.site

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

    make install HOSTPYTHON=./hostpython BLDSHARED=”arm-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-linux-gnueabi CROSS_COMPILE_TARGET=yes prefix=~/Python-3.4.1/_install

    Where config.site has the following content:
    ac_cv_file__dev_ptmx=no
    ac_cv_file__dev_ptc=no

    Everything works well until the last step – make install.
    There i get the following error:
    /usr/local/bin/python3.4: Error while finding spec for ‘ensurepip.__main__’ (: /home/user/Downloads/Python-3.4.1/build/lib.linux-arm-3.4/time.cpython-34m.so: cannot open shared object file: No such file or directory); ‘ensurepip’ is a package and cannot be directly executed

    Someone an idea whats going wrong and how to fix it?

    • Beyonlo says:

      I think that you need to apply the correct path for the Python 3.4.1.

      I would like to cross compile the 3.4.1 too, but still don’t have a patch for this version.

      Paul, do you have any idea when will have a patch for that version?

      Thank you!

      • Paul Gibson says:

        Hi Beyonlo,

        I’m not sure when a patch will be available (I certainly do not have time to do it at the moment). Feel free to develop the patch yourself and I will host it for you.

        Thank you,
        Paul

        • Beyonlo says:

          Hello Paul!

          Hmm.. unfortunately I’m don’t have an expertise to do that patch. But I checked now a patch example of 3.2.2 and I think that is not so difficult. I will to try and if I have success I will send you :)

          Anyway, I need your help, a bit.

          I have success compiling version 3.2.2 and 2.7.3, but as I will need twisted and sqlite, I prefer to use 2.7.3. Well, in the make process show a message that some modules was not found, like as zlib, _slite and so on, and in the middle of make install process happen some errors, but it finished ok. I would like to fix that warning/error in the make and make install process to have a working zlib (needed by twisted) and sqlite to access my sqlite3 database on my embedded.

          Please, if you can to take a look quickly in my compiling process and give me a feed back I will be happy!

          Here just parts where have warnings/errors (it is few lines): http://dpaste.com/01JTCDJ
          Here the complete command line compiling process, including my complete script compilation: http://pastebin.com/Fsxk3ZQ2
          Here my script: http://dpaste.com/2P6K7R0
          Here my config.log: http://paste2.org/0jb17dj1

          Thank you so much!

          • Paul Gibson says:

            Hi Beyonlo,

            Please look at the section titled “Building SQLLite and other dependencies”. A user called Lothsahn’s managed to get it working and provided these instructions. Please look for his posts about this issue and let me know your results.

            Thanks,
            Paul

            • Beyonlo says:

              Hello Paul,

              I read dozens of times that few lines about “Building SQLLite and other dependancies” and I tried many times to do that without success to works sqlite and ctypes. Still show error:

              ————————————————-

              checking whether we are cross compiling… configure: error: in `/home/pi/Prj/python/arm/2.7.3/Python-2.7.3/build/temp.linux-x86_64-2.7/libffi':
              configure: error: cannot run C compiled programs.
              If you meant to cross compile, use `–host’.
              See `config.log’ for more details.
              Failed to configure _ctypes module

              Python build finished, but the necessary bits to build these modules were not found:
              _bsddb _curses _curses_panel
              _sqlite3 _ssl _tkinter
              bsddb185 bz2 dbm
              dl gdbm imageop
              nis readline sunaudiodev
              zlib
              To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

              ————————————————-

              I did exactally as described in the “Building SQLLite and other dependancies”. I downloaded of sqlite3 from sqlite.org and libffi from ftp://sourceware.org/pub/libffi/ and compiled both using the cross compiling with success and copied included files and libs to folders “include” and “lib” “one path up” of Python source, like as listed below.

              pi@pi:~/Prj/python/arm/2.7.3$ ls
              include lib Python-2.7.3 Python-2.7.3.tar Python-2.7.3-xcompile.patch
              pi@pi:~/Prj/python/arm/2.7.3$ ls include/
              access.c accessTableEmployee.cpp ffi.h ffitarget.h sqlite3ext.h sqlite3.h
              pi@pi:~/Prj/python/arm/2.7.3$ ls lib/
              libffi-3.1 libffi.a libffi.la libffi.so libffi.so.6 libffi.so.6.0.2 libsqlite3.a libsqlite3.la libsqlite3.so libsqlite3.so.0 libsqlite3.so.0.8.6
              pi@pi:~/Prj/python/arm/2.7.3$

              Here the complete log: http://paste2.org/INk4DF6B

              What am I doing wrong?

              Thank you so much!

            • beyonlo says:

              Hello Paul,

              Did you removed my last reply here? Few hours ago I pasted the result of compilation with libffi and sqlite3 following the “Building SQLLite and other dependencies”.

              Anyway i have no success. I have to compiled the sqlite3 and libffi using my cross compiling and copied headers files and libs to include and lib dir one path up of Pyhon-2.7.3 source. In the removed post has details about this.

              I would like so much has ctypes and sqlite3 modules working.

              Thank you.

              • Paul Gibson says:

                Hi Beyonlo,

                I have not removed your post. All posts must be approved before they go onto the site.

                Paul

                • beyonlo says:

                  Hello Paul,

                  I read dozens of times that few lines about “Building SQLLite and other dependancies” and I tried many times to do that without success to works sqlite and ctypes. Still show error:

                  ————————————————-

                  checking whether we are cross compiling… configure: error: in `/home/pi/Prj/python/arm/2.7.3/Python-2.7.3/build/temp.linux-x86_64-2.7/libffi’:
                  configure: error: cannot run C compiled programs.
                  If you meant to cross compile, use `–host’.
                  See `config.log’ for more details.
                  Failed to configure _ctypes module

                  Python build finished, but the necessary bits to build these modules were not found:
                  _bsddb _curses _curses_panel
                  _sqlite3 _ssl _tkinter
                  bsddb185 bz2 dbm
                  dl gdbm imageop
                  nis readline sunaudiodev
                  zlib
                  To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

                  ————————————————-

                  I did exactally as described in the “Building SQLLite and other dependancies”. I downloaded of sqlite3 from sqlite.org and libffi from ftp://sourceware.org/pub/libffi/ and compiled both using the cross compiling with success and copied included files and libs to folders “include” and “lib” “one path up” of Python source, like as listed below.

                  pi@pi:~/Prj/python/arm/2.7.3$ ls
                  include lib Python-2.7.3 Python-2.7.3.tar Python-2.7.3-xcompile.patch
                  pi@pi:~/Prj/python/arm/2.7.3$ ls include/
                  access.c accessTableEmployee.cpp ffi.h ffitarget.h sqlite3ext.h sqlite3.h
                  pi@pi:~/Prj/python/arm/2.7.3$ ls lib/
                  libffi-3.1 libffi.a libffi.la libffi.so libffi.so.6 libffi.so.6.0.2 libsqlite3.a libsqlite3.la libsqlite3.so libsqlite3.so.0 libsqlite3.so.0.8.6
                  pi@pi:~/Prj/python/arm/2.7.3$

                  Here the complete log: http://paste2.org/INk4DF6B

                  What am I doing wrong?

                  Thank you so much!

                  • Paul Gibson says:

                    Hi Beyonlo,

                    The build is failing on the ctypes build:

                    checking whether we are cross compiling… configure: error: in `/home/pi/Prj/python/arm/2.7.3/Python-2.7.3/build/temp.linux-x86_64-2.7/libffi':
                    configure: error: cannot run C compiled programs.
                    If you meant to cross compile, use `–host’.
                    See `config.log’ for more details.
                    Failed to configure _ctypes module

                    The first thing that comes to mind is that you are using a uclibc toolchain. Can you try with a glibc toolchain and let me know the result?

                    Paul

                    • Beyonlo says:

                      Hello Paul.

                      I tried that test as you told me, here a piece:

                      ——-

                      config.status: executing include commands
                      config.status: executing src commands
                      /tmp/python/Python-2.7.3/Modules/_ctypes/cfield.c: In function ‘PyCField_FromDesc’:
                      /tmp/python/Python-2.7.3/Modules/_ctypes/cfield.c:50:29: warning: variable ‘length’ set but not used [-Wunused-but-set-variable]
                      Py_ssize_t size, align, length;
                      ^
                      /tmp/python/Python-2.7.3/Modules/_ctypes/libffi/src/closures.c: In function ‘dlmmap_locked’:
                      /tmp/python/Python-2.7.3/Modules/_ctypes/libffi/src/closures.c:416:17: warning: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result [-Wunused-result]
                      ftruncate (execfd, offset);
                      ^
                      /tmp/python/Python-2.7.3/Modules/_ctypes/libffi/src/closures.c:428:17: warning: ignoring return value of ‘ftruncate’, declared with attribute warn_unused_result [-Wunused-result]
                      ftruncate (execfd, offset);
                      ^

                      Python build finished, but the necessary bits to build these modules were not found:
                      _bsddb _curses _curses_panel
                      _sqlite3 _ssl _tkinter
                      bsddb185 bz2 dbm
                      dl gdbm imageop
                      nis readline sunaudiodev
                      zlib
                      To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

                      /usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py

                      ——-

                      Still show error of some modules (including sqlite3), but don’t show more error about ctypes. But I *changed* so much the params of ./configure and make. Look:

                      * In configure I changed:

                      Of: ./configure –host=x86_64-linux-gnu –target=arm-linux CC=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-gcc CXX=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-g++ AR=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-ar STRIP=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-strip RANLIB=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-ranlib CFLAGS=”-mtune=arm926ej-s -mfpu=vfp -Os -lpthread -lrt” LDFLAGS=${LDFLAGS} –prefix=$PREFIX

                      To: ./configure LDFLAGS=${LDFLAGS} –prefix=$PREFIX

                      * In make I changed:

                      Of: make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-gcc -shared” CROSS_COMPILE=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=x86_64-linux-gnu BUILDARCH=x86_64-linux-gnu

                      To: make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”gcc -shared” CROSS_COMPILE_TARGET=yes HOSTARCH=x86_64-linux-gnu BUILDARCH=x86_64-linux-gnu

                      * Ps: for this test I not included the includes libs of dependencies for sqlite, libffi and so on. Just default.

                      Please see the complete log here http://paste2.org/67bZOG07

                      I don’t know if I did the correct test as you would like to check. If not, tell me how I need to do the tests.

                      Thank you!

                    • Paul Gibson says:

                      Hi Beyonlo,

                      It seems that a uclibc toolchain cannot build ctypes in python for some reason. Your build has now gone further than before.

                      If you now add in the sqlite dependencies and try again it should complete the build. Please try this.

                      (Sorry for replying here, the thread depth exceeds 10)

                      Paul

  15. beyonlo says:

    Hello Paul,

    I will back to do the tests just thursday and i will add sqlite with gcc/g++ to x86. Anyway, what I need is the cross compiling to arm. Well, as you told me for some reason my cross compiling gcc/g++ (version 4.4) to ARMv5 not works with ctypes. Do you have any idea or tips where and how I can to investigate about this problem? To compile with success for x86 don’t solve my problem. I really need arm. Well, if I have success with everything: python and mostly stardard modules I think that have ctypes and sqlite working still is possible. I would like any tip about to do more tests.
    PS: Don’t matter if I use another version of python >= 2.7.3. But I tested 3.2.2 and I have the same problem with sqlite and ctypes.

    If you can, please reply to me I start the investigation and to do any other tests that you think to have python ctypes ans sqlite working in armv5. I really determined to use python in embedded :)

    Thank you so much

    • Paul Gibson says:

      Hi Beyonlo,

      I think you misunderstand me. I don’t want you to try x86. I want you to try a glibc toolchain for arm. You are currently using a uclibc toolchain. As far as I know, no-one on this page has had success with uclibc.

      Paul

      • beyonlo says:

        Hello Paul.

        Ok. Thank you to clarify to me. I will to try a glibc toolchain for arm and will report you. Problem that glibc will have a binary code bigger right? Other problem is that I’m using ARMv5 and I think that gcc/g++ for arm is just ARMv6, ARMv7 and ARMv8. Actually I am using davince gcc based on gcc 4.4 becouse that cpu is a arm9 (ARMv5) from davince.

        Thank you.

        • Paul Gibson says:

          Hi Beyonlo,

          Yes the glibc code will be much bigger. Another alternative for you is to use buildroot. buildroot will build you a uclibc rootfs and it will cross-compile python for you. I think this might be a better option for you.

          Paul

          • Beyonlo says:

            Hello Paul,

            I tried with glibc using cross compiling to arm (gnueabi) and I have the same error of using ulibc.

            My configure: $ ./configure –host=x86_64-linux-gnu –target=arm-linux CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ AR=arm-linux-gnueabi-ar STRIP=arm-linux-gnueabi-strip RANLIB=arm-linux-gnueabi-ranlib CFLAGS=”-mtune=arm926ej-s -mfpu=vfp -Os -lpthread -lrt” LDFLAGS=${LDFLAGS} –prefix=$PREFIX

            My make: $ make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-linux-gnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=x86_64-linux-gnu BUILDARCH=x86_64-linux-gnu

            The step where show the problem:

            ————–

            checking build system type… x86_64-pc-linux-gnu
            checking host system type… x86_64-pc-linux-gnu
            checking target system type… x86_64-pc-linux-gnu
            checking for a BSD-compatible install… /usr/bin/install -c
            checking whether build environment is sane… yes
            checking for a thread-safe mkdir -p… /bin/mkdir -p
            checking for gawk… gawk
            checking whether make sets $(MAKE)… yes
            checking for x86_64-linux-gnu-gcc… arm-linux-gnueabi-gcc
            checking whether the C compiler works… yes
            checking for C compiler default output file name… a.out
            checking for suffix of executables…
            checking whether we are cross compiling… configure: error: in `/home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/build/temp.linux-x86_64-2.7/libffi':
            configure: error: cannot run C compiled programs.
            If you meant to cross compile, use `–host’.
            See `config.log’ for more details.
            Failed to configure _ctypes module

            Python build finished, but the necessary bits to build these modules were not found:
            _bsddb _curses _curses_panel
            _sqlite3 _ssl _tkinter
            bsddb185 bz2 dbm
            dl gdbm imageop
            nis readline sunaudiodev
            zlib
            To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

            /usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py

            ————–

            Here the complete log of make: http://dpaste.com/3AKSD3H

            Any other idea to test/check?

            Thank you!

            • Beyonlo says:

              Hello Paul.

              Now works the ctypes, but without include dependencies. I just change my configure and make params in host and target.

              But sqlite3 still not works:

              ——————
              config.status: linking /home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/Modules/_ctypes/libffi/src/arm/ffitarget.h to include/ffitarget.h
              config.status: linking /home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/Modules/_ctypes/libffi/include/ffi_common.h to include/ffi_common.h
              config.status: executing depfiles commands
              config.status: executing libtool commands
              config.status: executing include commands
              config.status: executing src commands
              /home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/Modules/_ctypes/libffi/src/arm/ffi.c:205: warning: function declaration isn’t a prototype

              Python build finished, but the necessary bits to build these modules were not found:
              _bsddb _curses _curses_panel
              _sqlite3 _ssl _tkinter
              bsddb185 bz2 dbm
              dl gdbm imageop
              nis readline sunaudiodev
              zlib
              To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
              —————–

              I checked the setup.py and are there

            • Beyonlo says:

              Hello Paul.

              CTYPES WORKS!

              Now works the ctypes, but without include dependencies. I just change my configure and make params in host and target.

              But sqlite3 still not works:

              ——————
              config.status: linking /home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/Modules/_ctypes/libffi/src/arm/ffitarget.h to include/ffitarget.h
              config.status: linking /home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/Modules/_ctypes/libffi/include/ffi_common.h to include/ffi_common.h
              config.status: executing depfiles commands
              config.status: executing libtool commands
              config.status: executing include commands
              config.status: executing src commands
              /home/pi/Prj/KPabx/CompilingEnvironment/python/arm/2.7.3/Python-2.7.3/Modules/_ctypes/libffi/src/arm/ffi.c:205: warning: function declaration isn’t a prototype

              Python build finished, but the necessary bits to build these modules were not found:
              _bsddb _curses _curses_panel
              _sqlite3 _ssl _tkinter
              bsddb185 bz2 dbm
              dl gdbm imageop
              nis readline sunaudiodev
              zlib
              To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
              —————–

              I checked the setup.py and are there the env var PYTHON_XCOMPILE_DEPENDENCIES_PREFIX for that include and lib of dependencies. So I set PYTHON_XCOMPILE_DEPENDENCIES_PREFIX in configure for the path where are there include and lib of dependencies and still not works.

              My configure:
              ./configure –host=arm-davinci-linux-uclibcgnueabi –build=x86_64-build_unknown-linux-gnu –target=arm-davinci-linux-uclibcgnueabi CC=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-gcc CXX=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-g++ AR=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-ar STRIP=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-strip RANLIB=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-ranlib CFLAGS=”-mtune=arm926ej-s -mfpu=vfp -Os -lpthread -lrt” LDFLAGS=${LDFLAGS} –prefix=$PREFIX PYTHON_XCOMPILE_DEPENDENCIES_PREFIX=/tmp/python/arm/2.7.3

              My make:
              make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi-gcc -shared” CROSS_COMPILE=/opt/arm-davinci-linux-uclibcgnueabi/bin/arm-davinci-linux-uclibcgnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=x86_64-linux-gnu

              Here the my dir structure:
              pi@pi:/tmp/python/arm/2.7.3$ ls -la
              total 62224
              drwxr-xr-x 5 pi pi 4096 Jul 24 18:30 .
              drwxr-xr-x 8 pi pi 4096 Jul 24 18:30 ..
              drwxr-xr-x 2 pi pi 4096 Jul 24 18:30 include
              drwxr-xr-x 5 pi pi 4096 Jul 24 18:30 lib
              drwxr-x— 19 pi pi 4096 Jul 24 18:30 Python-2.7.3
              -rw-r–r– 1 pi pi 63682560 Jul 24 18:30 Python-2.7.3.tar
              -rw-r–r– 1 pi pi 11528 Jul 24 18:30 Python-2.7.3-xcompile.patch
              pi@pi:/tmp/python/arm/2.7.3$
              pi@pi:/tmp/python/arm/2.7.3$ find include/
              include/
              include/ffitarget.h
              include/sqlite3ext.h
              include/accessTableEmployee.cpp
              include/access.c
              include/sqlite3.h
              include/ffi.h
              pi@pi:/tmp/python/arm/2.7.3$ find lib/
              lib/
              lib/libsqlite3.la
              lib/libffi.la
              lib/libffi-3.0.10
              lib/libffi-3.0.10/include
              lib/libffi-3.0.10/include/ffitarget.h
              lib/libffi-3.0.10/include/ffi.h
              lib/libffi-3.1
              lib/libffi-3.1/include
              lib/libffi-3.1/include/ffitarget.h
              lib/libffi-3.1/include/ffi.h
              lib/libsqlite3.a
              lib/libffi.so.6
              lib/libsqlite3.so.0
              lib/pkgconfig
              lib/pkgconfig/libffi.pc
              lib/libffi.a
              lib/libffi.so
              lib/libsqlite3.so.0.8.6
              lib/libsqlite3.so
              lib/libffi.so.6.0.2
              pi@pi:/tmp/python/arm/2.7.3$

              The libffi and sqlite was compiled with the same cross compiling.

              Ps: In the setup.py are there a include path of libffi-3.0.10 in the PYTHON_XCOMPILE_DEPENDENCIES_PREFIX var. So I created the same dir libffi-3.0.10 inside lib and put the same as libffi-3.1.

              But still not sucess with sqlite!

              Any idea?

              Thank you

              • Beyonlo says:

                Hello Paul.

                It’s ok with dependencies sqlite3. The problem was really PYTHON_XCOMPILE_DEPENDENCIES_PREFIX that need to be in make and make install.

                I sugest you put about this PYTHON_XCOMPILE_DEPENDENCIES_PREFIX in that few lines about building sqlite and dependencies!

                Thank you so much!

  16. Jmzou says:

    Hi Paul.

    Python-2.7.3 hostCPU: netlogic mips64 xlp

    [root@localhost Python-2.7.3]# make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”/opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/bin/real-gnu-gcc -shared” CROSS_COMPILE=/opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/bin/real-gnu- CROSS_COMPILE_TARGET=yes HOSTARCH=/opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/mips64-unknown-linux-gnu BUILDARCH=x86_64-linux-gnu

    checking for sys/mman.h… (cached) yes
    checking for mmap… (cached) yes
    checking whether read-only mmap of a plain file works… yes
    checking whether mmap from /dev/zero works… yes
    checking for MAP_ANON(YMOUS)… yes
    checking whether mmap with MAP_ANON(YMOUS) works… yes
    configure: error: “libffi has not been ported to /opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/mips64-unknown-linux-gnu.”
    Failed to configure _ctypes module

    Python build finished, but the necessary bits to build these modules were not found:
    _bsddb _curses _curses_panel
    _sqlite3 _ssl _tkinter
    bsddb185 bz2 dbm
    dl gdbm nis
    readline sunaudiodev zlib
    To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

    • Jmzou says:

      /opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/bin/real-gnu-ar rc libpython2.7.a Modules/threadmodule.o Modules/signalmodule.o Modules/posixmodule.o Modules/errnomodule.o Modules/pwdmodule.o Modules/_sre.o Modules/_codecsmodule.o Modules/_weakref.o Modules/zipimport.o Modules/symtablemodule.o Modules/xxsubtype.o
      /opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/bin/real-gnu-ranlib libpython2.7.a
      /opt/zte/20110510/mips64_gcc4.5.2_glibc2.13.0_multi/bin/real-gnu-gcc -Xlinker -export-dynamic -o python \
      Modules/python.o \
      libpython2.7.a -lpthread -ldl -lpthread -lutil -lm

      Python build finished, but the necessary bits to build these modules were not found:
      _bsddb _curses _curses_panel
      _sqlite3 _ssl _tkinter
      bsddb185 bz2 dbm
      dl gdbm nis
      readline sunaudiodev zlib
      To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

  17. Kiesel says:

    Hi,

    could you help me figure out what I am missing? I am trying to compile python for a Fritzbox 7390.
    These are my environment variables:

    export CC=/home/kiesel/fritzcrosscompile/toolchain/target/bin/mips-linux-gcc
    export CFLAGS=”-O3 -march=24kec -mips16 -mdsp -static”
    export LDFLAGS=”-L/home/kiesel/fritzcrosscompile/toolchain/target/mips-linux-uclibc”
    export CPPFLAGS=”-I/home/kiesel/fritzcrosscompile/toolchain/target/mips-linux-uclibc/include”
    export CPP=”/home/kiesel/fritzcrosscompile/toolchain/target/bin/mips-linux-cpp”
    export CROSS_COMPILE=”mips-linux-”
    export ARCH=”mips-linux”
    export CONFIG=”–host i686-unknown-linux-gnu -target mips-linux”

    I then run “./config $CONF –prefix=/python” which finishes with return code 0.
    Afterwars I run “make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen CROSS_COMPILE_TARGET=yes” but this ends in a lot of:

    /home/kiesel/fritzcrosscompile/toolchain/build/mips_gcc-4.7.4_uClibc-0.9.33.2-nptl/mips-linux-uclibc/bin/../lib/gcc/mips-linux-uclibc/4.7.4/../../../../mips-linux-uclibc/bin/ld: /home/kiesel/fritzcrosscompile/toolchain/build/mips_gcc-4.7.4_uClibc-0.9.33.2-nptl/mips-linux-uclibc/bin/../lib/gcc/mips-linux-uclibc/4.7.4/crtbeginT.o: relocation R_MIPS_HI16 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
    /home/kiesel/fritzcrosscompile/toolchain/build/mips_gcc-4.7.4_uClibc-0.9.33.2-nptl/mips-linux-uclibc/bin/../lib/gcc/mips-linux-uclibc/4.7.4/crtbeginT.o: could not read symbols: Bad value
    collect2: error: ld returned 1 exit status

    Appending the -fPIC doesnt change a thing. Any help would be greatly appreciated.

    Thanks,
    Kiesel

  18. zb says:

    I cross compiled python 2.7.5 on embedded systemx kernel 2.6.12.5. It appears to work fine based on Trevor’s patch. (i had 3 minor changes to make which was MAX_REPEAT=65535) However, the GCC version shows the GCC of the host system and not the build system. I expected GCC 3.4.4 (build). Did i do something wrong? To test this, i renamed my normal GCC to gcc_test (which is 4.6.3) so it wouldn’t be found (verified with which). Then i did “make distclean” and tried again. To my surprise, it was again, the same same GCC.

    Thoughts!
    Thanks,
    /Z

    $ ./python
    Python 2.7.5 (default, Aug 31 2014, 23:35:05)
    [GCC 4.6.3] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>>

  19. khor says:

    Hi,

    I have been following your guide trying to crosscomplie Python-2.7.3 to powerpc. The crosscompiling works fine for the most part, the problem comes at the final step:

    Python build finished, but the necessary bits to build these modules were not found:
    _bsddb _curses _curses_panel
    _sqlite3 _ssl _tkinter
    bsddb185 bz2 dbm
    dl gdbm imageop
    nis readline sunaudiodev
    zlib
    To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

    I have tried to start compiling with the –with-zlib flag, but that returns:

    configure: WARNING: unrecognized options: –with-zlib

    I have tried some google searching and find the suggestion to comment some lines out from the Setup file located inside /Modules, but that does not seem to work either. Later I found out that this is one of the lines the Python-2.7.3-xcompile.patch
    is editing.

    I do have zlib, python-dev and build essential installed. Any idea what else could the problem come from?

    Thanks

    Khor

  20. Paul Gibson says:

    Hi Khor,

    Sorry, I’m very busy at the moment. Do you have zlib1g-dev installed on the host?

    Paul

  21. khor says:

    Hi Paul,

    I actually succeded in building zlib, by switching to Python-2.6.6. instead.

    Thanks

    Khor

  22. wang says:

    Hi Paul,

    I want to know .

    Thanks

    Khor

  23. wang says:

    Hi,Paul?

    I want to ask you 2 questions:


    Building SQLLite and other dependancies

    /include <– header files go here

    /lib <– shared object files go here

    /Python-2.7.3 <—Python sources go here during compile
    "

    1. what does "base directory" mean, can you give an example like "/data/data/sqlite3" ?
    2.?if "/data/data/sqlite3" is my sqlite install path ?,and the"/include” variable should add it to which file (is setup.py) ?

    btw, can you speak Chinese ?
    thanks !!

    • Paul Gibson says:

      Hi Khor,

      1. The base directory is the Python directory where you extracted the source code. In your case it would be Python-2.7.3
      2. Just try it with the above. Just copy the SQLIte3 files into the directories and see if it works.

      Sorry, I don’t speak Chinese.

      Paul

  24. kanchan says:

    Dear,
    i want to do cross compilation of python file for arm 9..so i have followed the above procedure but i am getting following error..

    make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-linux-gcc -shared” CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=i686-linux-gnu

    arm-linux-gcc -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE \
    -DSVNVERSION=”\”`LC_ALL=C echo Unversioned directory`\”” \
    -DHGVERSION=”\”`LC_ALL=C `\”” \
    -DHGTAG=”\”`LC_ALL=C `\”” \
    -DHGBRANCH=”\”`LC_ALL=C `\”” \
    -o Modules/getbuildinfo.o ./Modules/getbuildinfo.c
    arm-none-linux-gnueabi-gcc: directory”: No such file or directory
    : warning: missing terminating ” character
    ./Modules/getbuildinfo.c: In function ‘_Py_svnversion':
    ./Modules/getbuildinfo.c:63: error: missing terminating ” character
    ./Modules/getbuildinfo.c:63: error: expected expression before ‘;’ token
    make: *** [Modules/getbuildinfo.o] Error 1

  25. Srikanth says:

    Hi,
    Thanks for the step to step procedure to cross compiling Python.
    I want to cross compile python 2.7.3 for PowerPC (32 bit machine) on x86 machine (Ubuntu 12.04 32 bit machine).
    I executed the following steps after patching Python 2.7.3 for cross compilation:

    CC=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-gcc” CXX=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-g++” AR=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-ar” RANLIB=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-ranlib” ./configure –host=powerpc-linux-gnu –build=i686-linux-gnu –prefix=/python

    make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-gcc -shared” CROSS_COMPILE=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-” CROSS_COMPILE_TARGET=yes HOSTARCH=powerpc-linux-gnu BUILDARCH=i686-linux-gnu

    make install HOSTPYTHON=./hostpython BLDSHARED=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-gcc -shared” PATH=”${PATH}” CROSS_COMPILE=”/opt/usr/local/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-” CROSS_COMPILE_TARGET=yes prefix=~/Python-2.7.3/_install

    While installing, I found the following errors:

    PYTHONPATH=~/Python-2.7.3/_install/lib/python2.7 \
    ././hostpython -Wi -tt ~/Python-2.7.3/_install/lib/python2.7/compileall.py \
    -d ~/Python-2.7.3/_install/lib/python2.7 -f \
    -x ‘bad_coding|badsyntax|site-packages|lib2to3/tests/data’ \
    ~/Python-2.7.3/_install/lib/python2.7
    Traceback (most recent call last):
    File “/root/Python-2.7.3/_install/lib/python2.7/compileall.py”, line 16, in
    import struct
    File “/root/Python-2.7.3/_install/lib/python2.7/struct.py”, line 1, in
    from _struct import *
    ImportError: /root/python_build/Python-2.7.3/build/lib.linux-i686-2.7/_struct.so: ELF file data encoding not little-endian
    make: [libinstall] Error 1 (ignored)
    PYTHONPATH=~/Python-2.7.3/_install/lib/python2.7 \
    ././hostpython -Wi -tt -O ~/Python-2.7.3/_install/lib/python2.7/compileall.py \
    -d ~/Python-2.7.3/_install/lib/python2.7 -f \
    -x ‘bad_coding|badsyntax|site-packages|lib2to3/tests/data’ \
    ~/Python-2.7.3/_install/lib/python2.7
    Traceback (most recent call last):
    File “/root/Python-2.7.3/_install/lib/python2.7/compileall.py”, line 16, in
    import struct
    File “/root/Python-2.7.3/_install/lib/python2.7/struct.py”, line 1, in
    from _struct import *
    ImportError: /root/python_build/Python-2.7.3/build/lib.linux-i686-2.7/_struct.so: ELF file data encoding not little-endian
    make: [libinstall] Error 1 (ignored)
    PYTHONPATH=~/Python-2.7.3/_install/lib/python2.7 \
    ././hostpython -Wi -t ~/Python-2.7.3/_install/lib/python2.7/compileall.py \
    -d ~/Python-2.7.3/_install/lib/python2.7/site-packages -f \
    -x badsyntax ~/Python-2.7.3/_install/lib/python2.7/site-packages
    Traceback (most recent call last):
    File “/root/Python-2.7.3/_install/lib/python2.7/compileall.py”, line 16, in
    import struct
    File “/root/Python-2.7.3/_install/lib/python2.7/struct.py”, line 1, in
    from _struct import *
    ImportError: /root/python_build/Python-2.7.3/build/lib.linux-i686-2.7/_struct.so: ELF file data encoding not little-endian
    make: [libinstall] Error 1 (ignored)
    PYTHONPATH=~/Python-2.7.3/_install/lib/python2.7 \
    ././hostpython -Wi -t -O ~/Python-2.7.3/_install/lib/python2.7/compileall.py \
    -d ~/Python-2.7.3/_install/lib/python2.7/site-packages -f \
    -x badsyntax ~/Python-2.7.3/_install/lib/python2.7/site-packages
    Traceback (most recent call last):
    File “/root/Python-2.7.3/_install/lib/python2.7/compileall.py”, line 16, in
    import struct
    File “/root/Python-2.7.3/_install/lib/python2.7/struct.py”, line 1, in
    from _struct import *
    ImportError: /root/python_build/Python-2.7.3/build/lib.linux-i686-2.7/_struct.so: ELF file data encoding not little-endian
    make: [libinstall] Error 1 (ignored)
    PYTHONPATH=~/Python-2.7.3/_install/lib/python2.7 \
    ././hostpython -Wi -t -c “import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()”
    Traceback (most recent call last):
    File “”, line 1, in
    File “/root/Python-2.7.3/_install/lib/python2.7/lib2to3/pygram.py”, line 11, in
    from .pgen2 import driver
    File “/root/Python-2.7.3/_install/lib/python2.7/lib2to3/pgen2/driver.py”, line 21, in
    import logging
    File “/root/Python-2.7.3/_install/lib/python2.7/logging/__init__.py”, line 26, in
    import sys, os, time, cStringIO, traceback, warnings, weakref
    ImportError: /root/python_build/Python-2.7.3/build/lib.linux-i686-2.7/time.so: ELF file data encoding not little-endian
    make: [libinstall] Error 1 (ignored)

    But, all the binaries are libraries are generated to ‘_install’ directory. When I run these binaries in the TARGET machine, I am able to see python version is upgraded to 2.7.3. But, when I run ‘help()’ command from Python prompt, I got ‘Segmentation fault’.

    Can you please help me in identifying the problem?

    Thanks in advance.

    Regards,
    Srikanth.

    • Marty says:

      I see the same file. When I do `file _struct.so` I see
      _struct.so: ELF 32-bit MSB shared object, PowerPC or cisco 4500. version 1 (SYSV) or cisco 4500, dynamically linked, not stripped.

      I believe MSB = big endian which is correct for PowerPCm but the ImportError says is it looking for a little endian file. Why is it looking for a little endian file? I’ve tried various combinations of flags, but they all seem to be set right.

  26. Brian says:

    I was looking to cross compile Python for Android 3.4. I notices you have some 3.3 scripts, but those are not working with the 10c android NDK we have. We are getting errors with the PY_FORMAT_LONG_LONG not being defined.

    Any help would be appreciated. I am new to patches and cross compiling like this.

  27. I am having a similar problem as posted above running on Arm linux system. I cross compiled python with poky tool chain. I have setup PYTHONHOME to point to the python2.7/lib where site.py is but I still get this error. I am not sure what else to look for

    “ImportError: No module named site”.

    Has anybody faced a similar problem?

  28. […] How do i cross compile a python module for the ARM architecture? i have cross-compiled python as suggested by http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html […]

  29. I’ve succeeded to port Python 3.4.3 on MIPS with uClibc. The steps have been published here:
    http://changyuheng.me/2015/11/05/cross-compiling-python-3-4-3-for-mipsel/

Leave a Reply

(required)