Cross Compiling Python for Embedded Linux
来源:互联网 发布:淘宝客服一直不回消息 编辑:程序博客网 时间:2024/05/22 02:00
http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
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.
This page has been translated into <a href=”http://www.
Firstly, download the Python that you want to use from http://www.python.org/
Unpack the Python package using tar:
This will create a directory called Python-2.7.2. Goto the directory:
Then run these commands to build the host components:
make python Parser/pgen
mv python hostpython
mv Parser/pgen Parser/hostpgen
make distclean
Download the correct patch for your version of Python:
- Python-2.6.6-xcompile.patch
- Python-2.7.2-xcompile.patch (With ctypes thanks to Jaux (jaux.net)
- Python-2.7.3-xcompile.patch ( Thanks to Lothsahn)
- Python-3.1.1-xcompile.patch
- Python-3.1.2-xcompile.patch
- Python-3.1.3-xcompile.patch
- Python-3.2.2-xcompile.patch
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.
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:
…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:
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:
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.
- Cross Compiling Python for Embedded Linux
- Cross Compiling Python for Embedded Linux
- Cross Compiling Python for Embedded Linux
- Cross-Compiling Qt for Embedded Linux Applications
- Cross-compiling for ARM
- Cross-Compiling Under Linux
- cross compiling in Linux for android(arm_linux) platform
- Cross compiling wxDFB-2.8.11 for ARM-Linux
- cross-compiling for iPhone dev
- cross-compiling for iPhone dev
- Cross compiling Libx264 for ARM
- Cross Compiling For ARM With Autoconf
- Cross-compiling GNU libmicrohttpd for OpenWRT
- Cross-compiling TensorFlow for the Raspberry Pi
- Howto - Cross Compiling in Linux using MingW32
- cross-compiling FFmpeg through Ubuntu Linux
- about compiling python for android
- Cross-compiling Apache httpd 2.2.19 for uclibc
- oracle版本及字符集查询
- IT名企面试系列之腾讯笔试题
- oracle10g异常日志查看
- CKPT的工作机制
- 【实用】CMD关机、重启命令
- Cross Compiling Python for Embedded Linux
- 深入研究java中的静态代理和动态代理
- VC中使用ADO访问数据库技术程序实现方法
- int to string
- 实例详解 DB2 排序监控和调优
- oracle正则表达式匹配手机特号
- 根据ip获取城市
- YII 高级查询
- x-webkit-speech 语音输入