Cross Compiling Python for Embedded Linux

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.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.

内容概要:本文围绕基于风光储能和需求响应的微电网日前经济调度问题,提出了一套完整的Python代码实现方案。研究综合考虑风能、光伏等可再生能源的出力不确定性、储能系统的动态充放电特性以及需求侧响应机制,构建了以最小化系统综合运行成本为目标的优化调度模型。该模型充分体现了对可再生能源的高效消纳、系统经济性提升与供需平衡调控的能力,通过Python编程结合优化求解器实现了模型的求解与仿真验证,为微电网能量管理系统的设计与科研分析提供了可复现的技术路径与实践参考。; 适合人群:具备一定Python编程基础和电力系统优化调度知识的科研人员、工程技术人员及高校电气工程、能源系统等相关专业的研究生。; 使用场景及目标:①应用于微电网、智能配电网及综合能源系统的科研建模与仿真分析;②帮助读者深入理解含高比例可再生能源的电力系统日前调度建模方法、目标函数构造与约束条件处理技巧;③为实际工程中实现低碳、经济、可靠的微电网运行提供算法支持与决策依据。; 阅读建议:建议读者结合文档中的代码实例,系统学习优化模型的数学表达与编程实现过程,重点关注变量定义、目标函数构建、系统约束(如功率平衡、储能动态、机组出力等)的编码实现,并尝试调整负荷、新能源出力等输入数据进行多场景仿真,以深入掌握微电网调度策略的灵敏度分析与优化效果评估方法。
### Spring源码面试终结者:31道核心题,源码级拆解IOC与AOP 这份资源不是“面试八股文”,而是对Spring、Spring Boot核心原理的**源码级深度拆解**。网上面试题答案大多浮于表面,无法应对面试官的连环追问。我结合源码阅读和实战踩坑,整理了这份**近10万字的硬核指南**,系统梳理了大厂面试中最棘手的31道Spring核心题。 **【资源核心内容】** - **IOC与DI王者解析**:深入BeanFactory与ApplicationContext层级设计,对比三种依赖注入方式,并用图文拆解三级缓存解决循环依赖的源码流程。 - **AOP与事务底层原理**:彻底讲透动态代理选择策略,深度分析@Transactional失效的10大经典场景及源码级解决方案。 - **Spring MVC与自动装配**:从DispatcherServlet的9大组件到SpringBoot的SPI机制,理清自动配置的完整加载链路。 - **高频追问与满分话术**:每道题配有“低分vs高分回答”对比,帮你精准拿捏面试官想要的“源码级理解”。 **【特色】** 拒绝罗列概念,每道题都从“核心考点”出发,深入到AbstractApplicationContext、TransactionInterceptor等Spring源码,帮助你在理解设计思想的同时,具备手写简易IOC容器的能力。 **【适合谁看】** 备战阿里、字节、美团等大厂面试的Java开发;对Spring原理一知半解,想系统提升源码阅读能力的开发者;希望从“会用”进阶到“懂原理”的技术人。 希望这份整理能帮你构建完整的Spring知识体系,轻松应对面试官的灵魂追问!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值