Leon
Leon

Reputation: 2069

How to pre-install a Python package into a OpenWRT custom image?

I'm developing a router and need a Python module snmp_passpersist to be pre-installed.

The original source is coded in python2, so I modified it as to adapt to python3, and need to pre-install into the product image.

I know how to install a Python module onto a running live environment by means of pip and a setup.py that come with original source, but now I'm in the buildroot env of OpenWRT.

I read through the customizing package overview of OpenWRT, but it is for C language and binary executables.

It looks like that some more steps should be done with a Python module/package instead of a cp command, e.g. compiling *.py file into *.pyc, and making a egg file with a lot of package info, etc.

Maybe it works to copy simply the egg file into the target lib folder, but I worry about there will be no version information in the PIP environment.

I want to know the correct/formal way.

Upvotes: 1

Views: 1764

Answers (1)

Justin Yu
Justin Yu

Reputation: 61

You should follow an official python package from Openwrt

Add the include makefile for python

include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include ../python3-package.mk

There is some built-in command for the makefile, ex: $(eval $(call Py3Package,python3-curl))

Pre-built the python package and you can get this in a custom image

Ex: https://github.com/openwrt/packages/blob/openwrt-21.02/lang/python/python-curl/Makefile

Upvotes: 1

Related Questions