Difference between revisions of "Python development"

From ArmadeusWiki
Jump to: navigation, search
(GUI)
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
= Basic usages =
 
 
On this page you will learn how to create your first Python script for your Armadeus board. [[Image:Python_logo.png]]
 
On this page you will learn how to create your first Python script for your Armadeus board. [[Image:Python_logo.png]]
  
 
==Installation==
 
==Installation==
Python interpreter and libraries are not installed in the default APF9328 rootfs. Currently it increases the rootfs size by 6 MBytes and so, without cleanup, '''it won't fit in the old APF9328 FLASH size (8 MBytes)'''.<br>
+
* Python interpreter and libraries are not installed in the default APF rootfs:
So for the moment, if you have an 8MB FLASH, you can only use it from a NFS or a MMC/SD rootfs.<br>
+
** Currently it increases the rootfs size by 6 MBytes and so, without cleanup, '''it won't fit in the old APF9328 boards with 8 MBytes FLASH size'''. So for the moment, if you have an 8MB FLASH, you can only use it from a [[Network_Configuration#Boot_from_NFS | NFS]] or [[MultiMediaCard#Booting_from_MMC.2FSD | a MMC/SD rootfs]]. If your are a Python expert you can still delete some files in $ARMADEUS_ROOTFS/usr/lib/python2.7/... and tell us what isn't mandatory and uses a lot of space for nothing.
'''Python''' version installed by Buildroot is '''2.4'''.<br>
+
** On the APF27/51/28/6, you can activate it without concerning about the FLASH size.
If your are a Python expert you can still delete some files in $ROOTFS/usr/lib/python2.4/... and tell us what isn't mandatory and uses a lot of space for nothing.
+
* Python version available in latest Buildroot is '''2.7'''.
  
 
* Launch Buildroot's menuconfig:
 
* Launch Buildroot's menuconfig:
<source lang="bash">
+
<pre class="host">
armadeus$ make menuconfig
+
$ make menuconfig
</source>
+
</pre>
* In
+
<pre class="config">
[[Image:Menuconfig_package.png]] <br>  
+
Target packages  --->
and in <br>  
+
    Interpreter languages and scripting  --->
[[Image:Menuconfig_package_scripting.png]] <br>  
+
        [*] python
choose <br>  
+
            python module format to install (.pyc compiled sources only)  --->
[[Image:Menuconfig_package_python.png]] <br>
+
            core python modules  --->
* then save your configuration and build your system:
+
            external python modules  --->
<source lang="bash">
+
</pre>
armadeus$ make
+
 
</source>
+
* then save your configuration and rebuild your system:
* copy generated rootfs to your NFS directory or on your MMC/SD. If you already have an existing rootfs then just make a:
+
<pre class="host">
armadeus$ tar xf buildroot/binaries/armadeus/rootfs.tar -C /local/export/
+
$ make
Here ''/local/export/'' is my NFS exported directory.
+
</pre>
 +
* reflash you rootfs or, if needed, copy it to your NFS directory or on your MMC/SD: [[Network_Configuration#Boot_from_NFS | Booting from NFS]] or [[MultiMediaCard#Booting_from_MMC.2FSD | Booting from MMC/SD]].
  
 
==Source code==
 
==Source code==
Line 30: Line 30:
  
 
<source lang=python>
 
<source lang=python>
import sys
+
import sys
 
   
 
   
print "APF9328 says: Hello World ! ;-)"
+
    print "APF says: Hello World ! ;-)"
sys.exit(0)
+
    sys.exit(0)
 
</source>
 
</source>
 
* Save it as hello.py
 
* Save it as hello.py
  
==Compilation==
+
===Compilation===
 
Not needed. Transforming python script in executables hasn't been tested yet.
 
Not needed. Transforming python script in executables hasn't been tested yet.
  
 
==Running==
 
==Running==
* Copy your ''hello.py'' script on your NFS export directory or on your MMC/SD
+
* Copy your ''hello.py'' script on your target through TFTP or NFS export dir or your MMC/SD
 
* then on your APF console, launch it:
 
* then on your APF console, launch it:
 +
<pre class=apf>
 
  # python hello.py
 
  # python hello.py
  APF9328 says: Hello World ! ;-)
+
  APF says: Hello World ! ;-)
 
  #
 
  #
 +
</pre>
  
Now it's up to you ! ;-) But keep in mind that Python is extremly powerfull and libraries rich, so if you don't pay attention to memory usage of your scripts, you can easily reach the APF9328 memory size limit: 16 MBytes.
+
Now it's up to you !! But keep in mind that Python is extremely powerful and libraries rich, so if you don't pay attention to memory usage of your scripts, you can easily reach the APF9328 RAM size limit: 16 MBytes. On the APF27/51/28/6, it will be much more difficult ;-).
  
= Advanced usages =
+
== Advanced usages ==
 +
=== Disabling modules ===
  
== Installing modules ==
+
Defaults python modules can be enabled/disabled by Buildroot menuconfig.
  
Default python package on buildroot is minimal, for certain usage, it necessary to install more modules. Here a list of module tested on apf9328 :
+
=== Installing modules ===
  
===pyserial===
+
Default Python installation on Buildroot is "minimal"; for certain usage, it's necessary to install more modules. Here a list of modules tested on the APF9328 :
This module is used to communicate through serial port (rs232). The package is really simple to install. Just download the module here [http://www.zlib.net/] and unzip it on card (or on nfs filesystem). Once uncompressed just type :
+
<source lang="bash">
+
# python setup.py install
+
</source>
+
  
Under the pyserial directory. Once installed, this directory is no longer needed.
+
====pyserial====
 +
This module is used to communicate through serial port (RS232). The package is really simple to install:
 +
<pre class="host">
 +
$ make menuconfig
 +
</pre>
 +
<pre class="config">
 +
Target packages  --->
 +
    Interpreter languages and scripting  --->
 +
        [*] python
 +
            ...
 +
            external python modules  --->
 +
                ...
 +
                [*] python-serial
 +
</pre>
  
=Links=
+
===GUI===
 +
* To develop Graphical User Interface with Python you have the choice:
 +
** text like ones: curses, [http://urwid.org/index.html urwid], [http://www.npcole.com/npyscreen/ npyscreen]
 +
** basic graphical one: [[Pygame]], [[TkInter]]
 +
** advanced graphical ones: [[PySide]] (Qt), [[WxPython]]
 +
 
 +
==Links==
 
* [http://www.python.org/doc/ Python documentation]
 
* [http://www.python.org/doc/ Python documentation]
 +
* [https://wiki.python.org/moin/GuiProgramming GUI in Python]
 
* [[Network_Configuration | NFS server installation]]
 
* [[Network_Configuration | NFS server installation]]
 
* [[MMC/SD | Connect a MMC/SD card to your APF board]]
 
* [[MMC/SD | Connect a MMC/SD card to your APF board]]
  
<br>[[Image:FrenchFlag.png]][[Fr:Développement python| Cette page en français]]
+
[[Category:Python]]
 
+
[[Category:Programming language]]
 
[[Category:Software]]
 
[[Category:Software]]
[[Category:Programming language]]
 

Latest revision as of 14:30, 21 July 2014

On this page you will learn how to create your first Python script for your Armadeus board. Python logo.png

Installation

  • Python interpreter and libraries are not installed in the default APF rootfs:
    • Currently it increases the rootfs size by 6 MBytes and so, without cleanup, it won't fit in the old APF9328 boards with 8 MBytes FLASH size. So for the moment, if you have an 8MB FLASH, you can only use it from a NFS or a MMC/SD rootfs. If your are a Python expert you can still delete some files in $ARMADEUS_ROOTFS/usr/lib/python2.7/... and tell us what isn't mandatory and uses a lot of space for nothing.
    • On the APF27/51/28/6, you can activate it without concerning about the FLASH size.
  • Python version available in latest Buildroot is 2.7.
  • Launch Buildroot's menuconfig:
$ make menuconfig
Target packages  --->
    Interpreter languages and scripting  --->
        [*] python
            python module format to install (.pyc compiled sources only)  --->
            core python modules  --->
            external python modules  --->
  • then save your configuration and rebuild your system:
$ make

Source code

  • First take your favorite editor/IDE and create the following script:
import sys
 
    print "APF says: Hello World ! ;-)"
    sys.exit(0)
  • Save it as hello.py

Compilation

Not needed. Transforming python script in executables hasn't been tested yet.

Running

  • Copy your hello.py script on your target through TFTP or NFS export dir or your MMC/SD
  • then on your APF console, launch it:
 # python hello.py
 APF says: Hello World ! ;-)
 #

Now it's up to you !! But keep in mind that Python is extremely powerful and libraries rich, so if you don't pay attention to memory usage of your scripts, you can easily reach the APF9328 RAM size limit: 16 MBytes. On the APF27/51/28/6, it will be much more difficult ;-).

Advanced usages

Disabling modules

Defaults python modules can be enabled/disabled by Buildroot menuconfig.

Installing modules

Default Python installation on Buildroot is "minimal"; for certain usage, it's necessary to install more modules. Here a list of modules tested on the APF9328 :

pyserial

This module is used to communicate through serial port (RS232). The package is really simple to install:

$ make menuconfig
Target packages  --->
    Interpreter languages and scripting  --->
        [*] python
            ...
            external python modules  --->
                ...
                [*] python-serial

GUI

Links