Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java.
There are three main Python packages for OpenWrt; python, python3 and micropython.
Main python package is much larger than python-mini and python-light packages so we suggest that you don't even try to install full version unless you have at least 50MB of free space on your flash storage.
If you are using Chaos Calmer then python-mini package is replaced by python-light package. Currently python package adds a lot of dependencies so we suggest that you don't even try to install full version, unless you have at least 50MB of free space on your flash storage.
After Barrier Breaker python package became:
The idea of python-light is that, whenever you move a Python built-in module from python-light into a separate package (like python-codecs), python-light gets lighter. The mechanism is fairly dynamic; you just need to add a new 'python-package-xxxxxxx.mk' file with some basic Makefile rules, and that's it.
People can choose to install python-base if they need like really-really-really-really basic python (a = b + c and maybe some other syntax). Then they can choose to install other optional packages.
All other packages depend on python-light, because that one has some common libs.
The above is also true for python3.
To compile all python modules into pyc issue this command:
python -m compileall
Make sure you have at least 7MB of free space on your internal storage!
Now my python scripts start under 1.5 seconds and previously it would take them 6-8 seconds!
If you have additional python modules installed you need to compile them also, so for me I needed to additionally run these commands:
python -m compileall /usr/lib/python2.7/site-packages/serial/*.py python -m compileall /usr/lib/python2.7/site-packages/serial/tools/*.py python -m compileall /usr/lib/python2.7/site-packages/serial/urlhandler/*.py
python-mini uses around 1.5 MB of compressed space on squashfs /overlay partition or 4.5 MB uncompressed in /tmp (tmpfs ram) partition.
To install python mini just use:
opkg update opkg install python-mini
python-light uses around 7.2 MB of space.
To install python-light just use:
opkg update opkg install python-light
Note: all these sizes are arbitrary and have been obtained from building an ar71xx image.
At the time of writing this doc (3rd of July), the python package is comprised of
All packages below, depend on python-light, so if you decide to install any of them, you'll get python-light too.
There is no general recipe that works for everyone and keeps Python small, so anyone wanting Python on a device will have to install it step-by-step depending on the features you'd want.
We hope python-light will accommodate most needs. This package will become lighter if it makes sense to split some other lib out of it.
If you don't have at least 7.5 MB of free space on your / partition (check with “df -h”) then install python-mini or python-light to your /tmp ram drive with:
Barrier Breaker:
opkg update opkg install python-mini -d ram export PATH=$PATH:/tmp/usr/bin/ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/usr/lib/
Chaos Calmer and later:
opkg update opkg install python-light -d ram export PATH=$PATH:/tmp/usr/bin/ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/usr/lib/
Python is part of the package feeds, so you need to make sure you have the Packages feed configured in feeds.conf or feeds.conf.default.
src-git packages https://github.com/openwrt/packages.git
And then:
cd <your-openwrt-folder> ./scripts/feeds update packages ./scripts/feeds install python <or python3 if you want that too>
Then you should have Python (and/or Python3) in your make menuconfig under Languages =⇒ Python
Note that you'll get a lot of Python/Python3 packages, as the ones detailed above, as they've been split to reduce size.