Open main menu

DAVE Developer's Wiki β

Changes

DESK-MX6UL-AN-0004: Using Python for Embedded applications

1,967 bytes added, 09:14, 10 January 2023
no edit summary
{{InfoBoxTop}}
{{AppliesToAXEL ULite AN}}
{{AppliesTo_SBC_Lynx_AN}}
{{AppliesTo_RIALTO_SBC_AN}}
{{InfoBoxBottom}}
{{ImportantMessage|text=This application note has been validated using the '''kit version''' in the History table.}}
!Development Kit version
|-
| {{oldid|14782| 1.0.10}}
| Oct 2021
|{{oldid|14780|DESK-MX6UL-L 1.0.1}}|-| 2.0.0| Apr 2022|[[DESK-MX6UL-L/General/Release_Notes#DESK-MX6UL-L_1L_3.0.10|DESK-MX6UL-L 13.0.10]]
|-
|}
As reported in [https://opensource.com/life/16/8/python-vs-cc-embedded-systems this] article ''The C/C++ programming languages dominate embedded systems programming, though they have a number of disadvantages. Python, on the other hand, has many strengths that make it a great language for embedded systems.''
This application note provides some examples of software packages installation that can be used for building an '''Industrial IoT Gateway''' adding <code>python3</code> libraries to the [[SBC_Lynx_SBC | SBC Lynx]] platform.
== Python on DESK ==
<code>python</code> and <code>python3</code> application are is already present on [[DESK-MX6UL-L/Development/Building_the_Yocto_BSP#Quick_reference | DESK-MX6UL-L]] <code>dave-image-devel</code> root file system. Moreover, a huge list of ''python'' packages can be installed in the target using the [https://en.wikipedia.org/wiki/DNF_(software) DNF] package manager: the [[DESK-MX6UL-AN-0003:_Package_Management_with_Yocto_and_DNF | DESK-MX6UL-AN-0003]] shows how to install ''rpm'' packages in the target from the [http://yocto.dave.eu/desk-mx6ul-l-1.0.1/ DAVE's Yocto repository server].
== Installing python packages ==
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# python3 --versionPython 3.5.5root@desk-mx6ul-axelulite:~# pip --versionpip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)root@desk-mx6ul-axelulite:~# easy3_install --versionsetuptools 39.0.0 from /usr/lib/python3.5/site-packages (Python 3.5)4root@desk-mx6ul-axelulitelynx:~#
</pre>
Due to older pip version, it is worth to update <code>pippip3</code> before proceedingis not present - ''by default'' - on standard root file system, but can be easily installed using python:
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# python curl https://bootstrap.pypa.io/get-m pip install .py -o get-pip.py % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0:00:01 --:--:-- 1846kroot@desk-mx6ul-lynx:~# python3 get-upgrade pip.py
Collecting pip
Downloading https://files.pythonhosted.org/packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-2021.3.41-py2.py3-none-any.whl (1.5MB7 MB) 100% |#####################| 1.7 MB 2.1 MB/s Collecting setuptools Downloading setuptools-60.5.0-py3-none-any.whl (958 kB) |###########| 958 kB 2.1.5MB 52kBMB/s Installing collected packages: pipCollecting wheel Found existing installation: pip 9Downloading wheel-0.037.3 Uninstalling pip1-9py2.0py3-none-any.3whl (35 kB)Installing collected packages: Successfully uninstalled wheel, setuptools, pip-9.0.3Successfully installed pip-2021.3.4You are using pip version 201 setuptools-60.35.4, however version 210 wheel-0.2.4 is available37.1You should consider upgrading via WARNING: Running pip as the 'pip install --upgrade piproot' commanduser can result in broken permissions and conflicting behaviour with the system package manager.root@desk-mx6ul-axeluliteIt is recommended to use a virtual environment instead: https:~# //pip --versionpip 20.3.4 from /usr/lib/python2pypa.7io/site-packageswarnings/pip (python 2.7)venvroot@desk-mx6ul-axelulitelynx:~#
</pre>
=== easy install===Even if After the installation, <code>easy_installpip3</code> tool [https://setuptools.pypa.io/en/latest/deprecated/easy_install.html has been deprecated], it is a useful tool still present in the typical python distributions. For the purposes of this Application Note, the tool has been used to install some python packages typically used in an Industrial Gateway equipment In this example, the following packages are installed using ''easy_install'': '''pyserial''' and '''pymodbus''' (latest version available for bus communications), '''[https://docsPython3 3.python-requests9.org/en/latest/ requests]''' (HTTP library), '''schema''', '''ssdp4''':
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# easy3_install pyserialpip3 --versionSearching for pyserialBest match: pyserial pip 21.3.4Adding pyserial 1 from /usr/lib/python3.9/site-packages/pip (python 3.4 to easy9)root@desk-mx6ul-install.pth filelynx:~# </pre>
Using /usr/lib/python3.5/site-packages== Virtual environments ==Processing dependencies for pyserialFinished processing dependencies for pyserialroot@desk-mx6ul-axelulite:~# easy3_install pymodbusSearching for pymodbusReading As explained on [https://pypidocs.python.org/simple/pymodbus/Downloading https://files.pythonhosted.org/packages/57/213/6c9b1cade55161444450bdde6e953edb819d984beafee8d4baefa4f0310ctutorial/pymodbus-2.5.3rc1-py2.py3-none-any.whl#sha256=e8cbf3594a8dd0f71c287e24d8365e69836c8d22cac5ab288110638fd2b9fda6Best match: pymodbus 2.5.3rc1Processing pymodbus-2.5.3rc1-py2.py3-none-any.whlInstalling pymodbus-2.5.3rc1-py2venv.py3-none-any.whl to /usr/lib/html python312.5/site-packageswriting requirements Virtual Environments and Packages] tutorial it is better to /usr/lib/python3.5/site''"create a virtual environment, a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages/pymodbus-2.5.3rc1-py3.5.egg/EGG-INFO/requires.txtAdding pymodbus 2.5.3rc1 to easy-install.pth fileInstalling pymodbus.server script to /usr/binInstalling pymodbus.console script to /usr/bin"''
Installed /usr/lib/python3.5/site-packages/pymodbus-2.5.3rc1-py3.5.eggProcessing dependencies for pymodbusSearching for six>=1.15.0Reading https://pypi.python.org/simple/six/Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl#sha256=8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254Best match: six 1.16.0Processing six-1.16.0-py2.py3-none-any.whlInstalling six-1.16.0-py2.py3-none-any.whl This avoids the problem related to /usr/lib/python3Applications that sometimes need a specific version of a library.5/site-packagesAdding six 1.16.0 In this way it is possible to easy-installthe required packages (with their specific version required) only in this ''virtual environment'' (which may differ from the ''root'' installation).pth file
Installed * for example, create the <code>virtual environment</usr/lib/python3.5/sitecode> named '''desk'''<pre class="board-packages/six-1.16.0-py3.5.eggFinished processing dependencies for pymodbusterminal">root@desk-mx6ul-axelulitelynx:~# easy3_install requestsSearching for requestsReading https://pypi.python.org/simple/requests/Downloading https://files.pythonhosted.org/packages/92/96/144f70b972a9c0eabbd4391ef93ccd49d0f2747f4f6a2a2738e99e5adc65/requests-2.26.0-py2.py3-none-any.whl#sha256=6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24Best match: requests 2.26.0Processing requests-2.26.0-py2.py3-none-any.whlInstalling requests-2.26.0-py2.py3-none-any.whl to /usr/lib/python3.5/site-packageswriting requirements to /usr/lib/python3.5/site-packages/requests-2.26.0-py3.5.egg/EGGm venv desk-INFO/requires.txtenvAdding requests 2.26.0 to easyroot@desk-install.pth file Installed /usr/lib/python3.5/site-packages/requests-2.26.0mx6ul-py3.5.eggProcessing dependencies for requestsSearching for urllib3<1.27,>=1.21.1Reading https://pypi.python.org/simple/urllib3/Downloading httpslynx://files.pythonhosted.org/packages/af/f4/524415c0744552cce7d8bf3669af78e8a069514405ea4fcbd0cc44733744/urllib3-1.26.7-py2.py3-none-any.whl#sha256=c4fdf4019605b6e5423637e01bc9fe4daef873709a7973e195ceba0a62bbc844Best match: urllib3 1.26.7Processing urllib3-1.26.7-py2.py3-none-any.whlInstalling urllib3-1.26.7-py2.py3-none-any.whl to /usr/lib/python3.5/site-packageswriting requirements to /usr/lib/python3.5/site-packages/urllib3-1.26.7-py3.5.egg/EGG-INFO/requires.txtAdding urllib3 1.26.7 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/urllib3-1.26.7-py3.5.eggSearching for charset-normalizer~=2.0.0Reading https://pypi.python.org/simple/charset-normalizer/Downloading https://files.pythonhosted.org/packages/3f/65/69e6754102dcd018a0f29e4db673372eb323ee504431125ab6c9109cb21c/charset_normalizer-2.0.6-py3-none-any.whl#sha256=5d209c0a931f215cee683b6445e2d77677e7e75e159f78def0db09d68fafcaa6Best match: charset-normalizer 2.0.6Processing charset_normalizer-2.0.6-py3-none-any.whlInstalling charset_normalizer-2.0.6-py3-none-any.whl to /usr/lib/python3.5/site-packageswhich pip3writing requirements to /usr/lib/python3.5/site-packages/charset_normalizer-2.0.6-py3.5.egg/EGG-INFO/requires.txtAdding charset-normalizer 2.0.6 to easy-install.pth fileInstalling normalizer script to /usr/bin Installed /usr/lib/python3.5/site-packages/charset_normalizer-2.0.6-py3.5.eggSearching for certifi>=2017.4.17Reading https://pypi.python.org/simple/certifi/Downloading https://files.pythonhosted.org/packages/05/1b/0a0dece0e8aa492a6ec9e4ad2fe366b511558cdc73fd3abc82ba7348e875/certifi-2021.5.30-py2.py3-none-any.whl#sha256=50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8Best match: certifi 2021.5.30Processing certifi-2021.5.30-py2.py3-none-any.whlInstalling certifi-2021.5.30-py2.py3-none-any.whl to /usr/lib/python3.5/site-packagesAdding certifi 2021.5.30 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/certifi-2021.5.30-py3.5.eggFinished processing dependencies for requestspip3root@desk-mx6ul-axelulitelynx:~# easy3_install schemaSearching for schemaReading https://pypi.python.org/simple/schema</pre>Downloading https://files.pythonhosted.org/packages/c7/64/497632c9dc3c1bc94a92d9cafdc5cbd21d011bb651952765195739129a49/schema-0.7.4-py2.py3-none-any.whl#sha256=cf97e4cd27e203ab6bb35968532de1ed8991bce542a646f0ff1d643629a4945dBest match: schema 0.7.4Processing schema-0.7.4-py2.py3-none-any.whlInstalling schema-0.7.4-py2.py3-none-any.whl to /usr/lib/python3.5/site-packageswriting requirements to * activate the <code>virtual environment</usr/lib/python3.5/site-packages/schema-0.7.4-py3.5.egg/EGG-INFO/requires.txtAdding schema 0.7.4 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/schema-0.7.4-py3.5.eggProcessing dependencies for schemaSearching for contextlib2code>=0.5.5Reading https://pypi.python.org/simple/contextlib2/Downloading https://files.pythonhosted.org/packages/76/56/6d6872f79d14c0cb02f1646cbb4592eef935857c0951a105874b7b62a0c3/contextlib2-21.6.0-py2.py3-none-any.whl#sha256<pre class=3fbdb64466afd23abaf6c977627b75b6139a5a3e8ce38405c5b413aed7a0471fBest match: contextlib2 21.6.0Processing contextlib2"board-21.6.0-py2.py3-none-any.whlInstalling contextlib2-21.6.0-py2.py3-none-any.whl to /usr/lib/python3.5/site-packagesAdding contextlib2 21.6.0 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/contextlib2-21.6.0-py3.5.eggFinished processing dependencies for schematerminal">root@desk-mx6ul-axelulitelynx:~# easy3_install ssdpSearching for ssdpReading https://pypi.python.org/simple/ssdp/Downloading https://files.pythonhosted.org/packages/1d/04/d761ea63c8cb9e0e8a37cc63df9ec39c8c6a0f77363d131035b694758a5d/ssdp-1.1.0-py2.py3-none-any.whl#sha256=dc91a844e54ba6b1a2f3be4d9a52302027f71719c5eb2c0e6fbd77e67e7343adBest match: ssdp 1.1.0Processing ssdp-1.1.0-py2.py3-none-any.whlInstalling ssdp-1.1.0-py2.py3-nonesource desk-any.whl to env/usrbin/lib/python3.5/site-packagesAdding ssdp 1.1.0 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/ssdp-1.1.0-py3.5.eggProcessing dependencies for ssdpFinished processing dependencies for ssdproot@desk-mx6ul-axelulite:~#activate
</pre>
 Then, add some useful IP packages like * check and update ''pip3'nmap''' or '''[https://scapy.readthedocs.io/en/latestin the the <code>virtual environment</ scapy]''' (network packet manipulation):code>
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# easy3_install nmapwhich pip3Searching for nmapReading https:/home/pypi.python.orgroot/simpledesk-env/nmapbin/pip3Downloading https://files.pythonhosted.org/packages/f8/6f/6813025bd575ebc771189afaab7c405fdf3f1febaa197525d5aa6fd88ac5/nmap(desk-0.0.1env) root@desk-py3mx6ul-none-any.whllynx:~#sha256=158de16af02043e1a2015662ad1710dfb46dadd2bea8e9d90ba16b78b6650098Best match: nmap 0.0.1Processing nmappython3 -0.0.1-py3m pip install -none-any.whlupgrade pipCollecting pipInstalling nmap Using cached pip-021.03.1-py3-none-any.whl to /usr/lib/python3.5/site-packagesAdding nmap 0.0.(1 to easy-install.pth file7 MB) Installed /usr/lib/python3.5/site-Installing collected packages/nmap-0.0.1-py3.5.eggProcessing dependencies for nmapFinished processing dependencies for nmaproot@desk-mx6ul-axelulite:~# easy3_install scapypipSearching for scapyReading https Attempting uninstall://pypi.python.org/simple/scapy/pipDownloading https Found existing installation://files.pythonhosted.org/packages/85/47/c919432ca258f354bb2c1e645623f891603f185bfc7563d4a21f6432e7ed/scapy-2.4pip 20.5.tar.gz#sha256=bc707e3604784496b6665a9e5b2a69c36cc9fb032af4864b29051531b24c8593Best match: scapy 2.4.53Processing scapy Uninstalling pip-220.4.5.tar.gzWriting /tmp/easy_install-vsqq0ans/scapy-2.4.5/setup.cfg3:Running scapy Successfully uninstalled pip-2.4.5/setup20.py -q bdist_egg --dist-dir /tmp/easy_install-vsqq0ans/scapy-2.4.5/egg3Successfully installed pip-dist-tmp-nauxdhas/usr/lib/python321.5/distutils/dist3.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'1 warnings.warn(msgdesk-env)creating /usr/lib/python3.5/siteroot@desk-mx6ul-packages/scapylynx:~# pip3 -2.4.5-py3.5.eggversionExtracting scapy-2pip 21.43.5-py3.5.egg to 1 from /usrhome/libroot/python3.5/site-packagesAdding scapy 2.4.5 to easydesk-install.pth fileInstalling scapy script to /usr/binInstalling UTscapy script to /usr/bin Installed /usrenv/lib/python3.59/site-packages/scapy-2pip (python 3.4.59)(desk-py3.5.eggProcessing dependencies for scapyFinished processing dependencies for scapyenv) root@desk-mx6ul-axelulitelynx:~#
</pre>
On top of that, some web packages are very useful for creating web application and remotely control* <code>setuptools</get information from the gateway: '''[https://bottlepy.org/docs/dev/ bottle]''' (lightweight WSGI micro web-framework), '''[https://pypi.org/project/fastapi/ fastapi]''' (high-performance web framework)code> can be upgraded too:
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# easy3_install bottleSearching for bottleReading https://pypi.python.org/simple/bottle/Downloading https://files.pythonhosted.org/packages/bf/44/aeafdd6ca05a8e1c3f91eeeb272a202d5cb1b3b23730a5ca686a81c48d24/bottlepip3 install -0.12.19-py3-none-any.whl#sha256=f6b8a34fe9aa406f9813c02990db72ca69ce6a158b5b156d2c41f345016a723dupgrade setuptoolsBest matchRequirement already satisfied: bottle 0setuptools in .12.19Processing bottle-0.12.19-py3-none-any.whlInstalling bottle-0.12.19-py3-none/desk-any.whl to /usrenv/lib/python3.59/site-packagesAdding bottle 0(49.122.19 to easy-install.pth fileInstalling bottle.py script to /usr/bin1)Collecting setuptoolsInstalled /usr/lib/python3.5/site Using cached setuptools-packages/bottle-0.12.19-py360.5.eggProcessing dependencies for bottleFinished processing dependencies for bottleroot@desk-mx6ul-axelulite:~# easy3_install fastapiSearching for fastapiReading https://pypi.python.org/simple/fastapi/Downloading https://files.pythonhosted.org/packages/92/a8/10d8a171afa66e6e8a5cfe82771d11c4c84a2a874c19c0b55c7099001fac/fastapi-0.68.2-py3-none-any.whl#sha256=36bcdd3dbea87c586061005e4a40b9bd0145afd766655b4e0ec1d8870b32555c(958 kB)Best matchInstalling collected packages: fastapi 0.68.2setuptoolsProcessing fastapi-0.68.2-py3-none-any.whl Attempting uninstall: setuptoolsInstalling fastapi-0.68 Found existing installation: setuptools 49.2-py3-none-any.whl to /usr/lib/python3.5/site-packages1writing requirements to /usr/lib/python3.5/site Uninstalling setuptools-packages/fastapi-0.6849.2-py3.5.egg/EGG-INFO/requires.txtAdding fastapi 0.68.2 to easy-install.pth file1:Installed /usr/lib/python3.5/site-packages/fastapi Successfully uninstalled setuptools-0.6849.2-py3.5.egg1Processing dependencies for fastapiSearching WARNING: Value for starlette==0scheme.14platlib does not match.2Reading Please report this to <https://pypi.pythongithub.orgcom/simplepypa/starlettepip/Downloading https:issues//files.pythonhosted.org/packages/15/34/db1890f442a1cd3a2c761f4109a0eb4e63503218d70a8c8e97faa09a5500/starlette-0.14.2-py3-none-any.whl#sha256=3c8e48e52736b3161e34c9f0e8153b4f32ec5d8995a3ee1d59410d92f75162ed10151>Best match distutils: starlette 0.14.2Processing starlette-0.14.2-py3-none-any.whlInstalling starlette-0.14.2-py3-none-any.whl to /usrhome/libroot/python3.5/sitedesk-packageswriting requirements to /usrenv/lib/python3.59/site-packages/starlette-0.14.2-py3.5.egg/EGG-INFO/requires.txtAdding starlette 0.14.2 to easy-install.pth file Installed sysconfig: /usr/lib/python3.59/site-packages/starlette-0.14.2-py3.5.eggSearching WARNING: Value for pydantic!=1scheme.7,!=1purelib does not match.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,Please report this to <2.0.0,>=1.6.2Reading https://pypigithub.python.orgcom/pypa/simplepip/pydanticissues/10151>Downloading https distutils:/home/files.pythonhosted.orgroot/packages/ff/74/54e030641601112309f6d2af620774e9080f99c7a15742fc6a0b170c4076/pydantic-1.8.2desk-py3-none-any.whl#sha256=fec866a0b59f372b7e776f2d7308511784dace622e0992a0b59ea3ccee0ae833Best match: pydantic 1.8.2Processing pydantic-1.8.2-py3-none-any.whlInstalling pydantic-1.8.2-py3-none-any.whl to /usrenv/lib/python3.59/site-packageswriting requirements to sysconfig: /usr/lib/python3.59/site-packages/pydantic-1.8.2-py3.5.egg/EGG-INFO/requires.txtAdding pydantic 1.8.2 to easy-install.pth file WARNING: Additional context: user = FalseInstalled /usr/lib/python3.5/site-packages/pydantic-1.8.2-py3.5.egg home = NoneSearching for typing-extensions> root =3.7.4.3NoneReading https://pypi.python.org/simple/typing-extensions/Downloading https://files.pythonhosted.org/packages/74/60/18783336cc7fcdd95dae91d73477830aa53f5d3181ae4fe20491d7fc3199/typing_extensions-3.10.0.2-py3-none-any.whl#sha256 prefix =f1d25edafde516b146ecd0613dabcc61409817af4766fbbcfb8d1ad4ec441a34NoneBest match: typingSuccessfully installed setuptools-extensions 3.10.0.2Processing typing_extensions-3.10.0.2-py3-none-any.whlInstalling typing_extensions-3.10.0.2-py3-none-any.whl to /usr/lib/python360.5/site-packagesAdding typing-extensions 3.10.0.2 to easy-install.pth file Installed /usr/lib/python3.5/site(desk-packages/typing_extensionsenv) root@desk-3.10.0.2mx6ul-py3.5.eggFinished processing dependencies for fastapilynx:~#
</pre>
and finally an MQTT client like Afterword, the [httphttps://www.eclipsepypi.org/pahoproject/wheel/ Eclipse paho MQTTwheel] package is worth to be installed toofor further package installation
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# easy3_install paho-mqttpip3 install wheelCollecting wheelSearching for paho Using cached wheel-mqttReading https://pypi0.python37.org/simple/paho1-mqtt/Downloading https://filespy2.pythonhosted.org/packages/32/d3/6dcb8fd14746fcde6a556f932b5de8bea8fedcb85b3a092e0e986372c0e7/pahopy3-mqttnone-1any.5.1.tar.gz#sha256=9feb068e822be7b3a116324e01fb6028eb1d66412bf98595ae72698965cb1caewhl (35 kB)Best matchInstalling collected packages: paho-mqtt 1.5.1wheelProcessing paho-mqtt-1 WARNING: Value for scheme.5platlib does not match.1Please report this to <https://github.tar.gzWriting com/tmppypa/easy_install-vkarrpqipip/paho-mqtt-1.5.1issues/setup.cfg10151>Running paho-mqtt-1.5.1 distutils: /setup.py -q bdist_egg --dist-dir home/tmproot/easy_installdesk-vkarrpqienv/lib/paho-mqtt-1python3.5.19/eggsite-dist-tmp-tt8lku70packagescreating sysconfig: /usr/lib/python3.59/site-packages/paho_mqtt-1 WARNING: Value for scheme.5purelib does not match.1-py3Please report this to <https://github.5.eggcom/pypa/pip/issues/10151>Extracting paho_mqtt-1.5.1 distutils: /home/root/desk-py3.5.egg to /usrenv/lib/python3.59/site-packagesAdding paho-mqtt 1.5.1 to easy-install.pth file Installed sysconfig: /usr/lib/python3.59/site-packages/paho_mqtt WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed wheel-10.537.1-py3.5.eggProcessing dependencies for paho(desk-mqttFinished processing dependencies for paho-mqttenv) root@desk-mx6ul-axelulitelynx:~#
</pre>
=== DNF pip package installation===In case For the purposes of some troubles (which can happens using <code>easy_install</code> or <code>pip</code>)this Application Note, other packages can be directly installed using <code>dnfpip3</code> from the already built ''rpm'' has been used to install some python packages built with Yocto:typically used in an Industrial Gateway equipment
For In this example, the following packages are installed '''pyserial''' and '''pymodbus''' (for installing bus communications), '''[https://flask.palletsprojects.com/en/2.0.x/ flask]''' or , '''[https://fastapi.tiangolo.com/ fastapi]''' (web framework), '''ujson[https://bottlepy.org/docs/dev/ bottle]''' (lightweight WSGI micro web-framework), ''' it is possible to use <code>dnf install <rpm[https://docs.python-package><requests.org/en/latest/ requests]''' (HTTP library), '''schema''', '''ssdp''', '''[https://scapy.readthedocs.io/en/latest/ scapy]''' (network packet manipulation), '''nmap''', '''[https://pypi.org/code>project/ujson/ ujson]''' (JSON framework):
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# dnf pip3 install python3pyserialCollecting pyserial Downloading pyserial-3.5-flaskLast metadata expiration check: 0:13:01 ago on Wed Oct 6 08:39:56 2021py2.Dependencies resolvedpy3-none-any.===================================================================whl (90 kB) Collecting fastapi Downloading fastapi-0.72.0-py3-none-any.whl (52 kB) |████████████████████████████████| 52 kB 77 kB/sCollecting pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2 Downloading pydantic-1.9.0-py3-none-any.whl (140 kB) |████████████████████████████████| 140 kB 2.1 MB/sCollecting starlette==0.17.1 Downloading starlette-0.17.1-py3-none-any.whl (58 kB) |████████████████████████████████| 58 kB 619 kB/sCollecting anyio<4,>=3.0.0 Downloading anyio-3.5.0-py3-none-any.whl (79 kB) |████████████████████████████████| 79 kB 797 kB/sCollecting typing-extensions>=3.7.4.3 Downloading typing_extensions-4.0.1-py3-none-any.whl (22 kB)Collecting sniffio>=1.1 Downloading sniffio-1.2.0-py3-none-any.whl (10 kB)Collecting idna>=2.8 Downloading idna-3.3-py3-none-any.whl (61 kB) |████████████████████████████████| 90 kB 780 kB/s Package Arch Version Repository SizeInstalling collected packages: pyserial WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user =False home =None root =None prefix =============================================================================NoneSuccessfully installed pyserial-3.5Installing(desk-env) root@desk-mx6ul-lynx:~# pip3 install pymodbusCollecting pymodbus python3 Downloading pymodbus-flask cortexa7hf_neon 02.125.23-r0 cortexa7hf 110 kInstalling dependencies: python3-click cortexa7hf_neon 6py2.7py3-r0 cortexa7hf 110 k python3none-itsdangerous cortexa7hf_neon 0any.24-r0 cortexa7hf 23 kwhl (154 kB) python3-jinja2 |████████████████████████████████| 154 kB 1.5 MB/s cortexa7hf_neon 2Collecting six>=1.15.10-r0 cortexa7hf 187 k0 python3 Downloading six-markupsafe cortexa7hf_neon 1.16.0-r0 cortexa7hf 25 k python3py2.py3-none-simplejson cortexa7hf_neon 3.13any.2-r0 cortexa7hf 50 kwhl (11 kB) python3-werkzeug cortexa7hf_neon 0Requirement already satisfied: pyserial>=3.144 in .1/desk-r0 cortexa7hf 375 k env/lib/python3.9/site-werkzeug-tests cortexa7hf_neon 0.14packages (from pymodbus) (3.1-r0 cortexa7hf 32 k5)Transaction SummaryInstalling collected packages: six, pymodbus WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user =False home =None root =None prefix =============================================================================Install 8 Packages Total download size: 912 kInstalled size: NoneSuccessfully installed pymodbus-2.5.3six-1.16.7 MIs this ok [y/N]: yDownloading Packages:0(1/8desk-env)root@desk-mx6ul-lynx: python3-itsdangerous~# pip3 install flaskCollecting flask Downloading Flask-2.0.242-py3-none-r0any.cortexa7hf_ 128 whl (95 kB/s ) | 23 ████████████████████████████████| 95 kB 422 kB 00:00/s(Collecting Werkzeug>=2/8): python3-flask.0 Downloading Werkzeug-2.0.12.2-r0py3-none-any.cortexa7hf_neon. 344 whl (288 kB/s ) | 110 ████████████████████████████████| 288 kB 00:002.1 MB/s(3/8): python3-click-6Collecting itsdangerous>=2.70 Downloading itsdangerous-r02.cortexa7hf_neon0.rpm 329 kB/s | 110 1-py3-none-any.whl (18 kB 00:00)(4/8): python3-jinja2-Collecting click>=7.1.2.10 Downloading click-r08.cortexa7hf_neon0.r 508 kB/s | 187 kB 00:00(5/8): python33-werkzeugpy3-testsnone-0any.14.1-r0.cortexa 137 whl (97 kB) |████████████████████████████████| 97 kB 226 kB/s | 32 kB 00:00(6/8): python3Collecting Jinja2>=3.0 Downloading Jinja2-markupsafe-13.0.3-r0py3-none-any.cortexa7hf_neo 318 whl (133 kB) |████████████████████████████████| 133 kB2.1 MB/s | 25 kB 00:00(7/8): python3Collecting MarkupSafe>=2.0 Downloading MarkupSafe-simplejson-32.0.131.2-r0tar.cortexa7hf_ 220 gz (18 kB/s | 50 kB 00:00)(8/8 Preparing metadata (setup.py)... doneBuilding wheels for collected packages: python3-werkzeugMarkupSafe Building wheel for MarkupSafe (setup.py) ... done Created wheel for MarkupSafe: filename=MarkupSafe-2.0.14.1-r0cp39-cp39-linux_armv7l.cortexa7hf_ne 684 kBwhl size=25720 sha256=4fa273af41ed51d0614beb76603162148fd15472aa0eb8c1c28a9c18ed137031 Stored in directory: /s | 375 kB 00home/root/.cache/pip/wheels/9f/6d/c8/1f59b07cf85ae842908006ec28f4477f7e4578df72c3eb0e46Successfully built MarkupSafeInstalling collected packages:00MarkupSafe, Werkzeug, Jinja2, itsdangerous, click, flask WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.2 click-8.0.3 flask-2.0.2 itsdangerous-2.0.1(desk-env) root@desk-mx6ul-lynx:~# pip3 install fastapiCollecting fastapi Downloading fastapi-0.72.0-py3-none-any.whl (52 kB) |████████████████████████████████| 52 kB 77 kB/sCollecting pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2 Downloading pydantic-1.9.0-py3-none----------------------------------------------------------any.whl (140 kB)Total 979 kB/s |████████████████████████████████| 912 140 kB 00:002.1 MB/sRunning transaction checkTransaction check succeededCollecting starlette==0.Running transaction testTransaction test succeeded17.Running transaction Preparing : 1/1 Installing : python3-werkzeugDownloading starlette-0.1417.1-r0py3-none-any.cortexa7hf_neon 1whl (58 kB) |████████████████████████████████| 58 kB 619 kB/8sCollecting anyio<4,>=3.0.0 Installing : python3Downloading anyio-3.5.0-werkzeugpy3-testsnone-0any.14whl (79 kB) |████████████████████████████████| 79 kB 797 kB/sCollecting typing-extensions>=3.7.1-r04.cortexa7hf_neon 2/83 Installing : python3Downloading typing_extensions-markupsafe-14.0.1-r0py3-none-any.cortexa7hf_neon 3/8whl (22 kB)Collecting sniffio>=1.1 Installing : python3-jinja2Downloading sniffio-1.2.100-py3-none-r0any.whl (10 kB)Collecting idna>=2.cortexa7hf_neon 4/8 Installing : python3-simplejsonDownloading idna-3.13.23-py3-none-r0any.cortexa7hf_neon 5whl (61 kB) |████████████████████████████████| 61 kB 770 kB/8s Installing collected packages: python3sniffio, idna, typing-itsdangerous-0.24-r0.cortexa7hf_neon 6/8extensions, anyio, starlette, pydantic, fastapi Installing WARNING: python3-click-6Value for scheme.platlib does not match.7-r0Please report this to <https://github.cortexa7hf_neon 7com/pypa/pip/issues/810151> Installing distutils: /home/root/desk-env/lib/python3-flask-0.12.29/site-r0packages sysconfig: /usr/lib/python3.cortexa7hf_neon 89/8site-packages Verifying WARNING: python3-flask-0Value for scheme.12purelib does not match.2-r0Please report this to <https://github.cortexa7hf_neon 1com/pypa/pip/issues/810151> Verifying distutils: /home/root/desk-env/lib/python3-click-6.79/site-r0.cortexa7hf_neon 2/8packages Verifying sysconfig: /usr/lib/python3-itsdangerous-0.249/site-r0.cortexa7hf_neon 3/8packages Verifying WARNING: Additional context: python3-jinja2-2.10-r0.cortexa7hf_neon 4/8 Verifying : python3user = False home = None root = None prefix = NoneSuccessfully installed anyio-werkzeug3.5.0 fastapi-0.1472.10 idna-r03.cortexa7hf_neon 5/8 Verifying : python33 pydantic-werkzeug-tests-01.149.0 sniffio-1-r0.cortexa7hf_neon 6/8 Verifying : python32.0 starlette-simplejson-30.1317.21 typing-r0.cortexa7hf_neon 7/8 Verifying : python3extensions-markupsafe-14.0-r0.cortexa7hf_neon 8/81(desk-env) root@desk-mx6ul-lynx:~# pip3 install bottleInstalled:Collecting bottle python3Downloading bottle-flask.cortexa7hf_neon 0.12.219-py3-r0 python3none-clickany.cortexa7hf_neon 6.7-r0whl (89 kB) |████████████████████████████████| 89 kB 724 kB/sInstalling collected packages: bottle python3-itsdangerousWARNING: Value for scheme.platlib does not match.cortexa7hf_neon 0Please report this to <https://github.24-r0com/pypa/pip/issues/10151> python3-jinja2.cortexa7hf_neon 2.10distutils: /home/root/desk-r0 env/lib/python3-markupsafe.cortexa7hf_neon 1.09/site-r0packages sysconfig: /usr/lib/python3-simplejson.cortexa7hf_neon 3.13.29/site-r0packages python3-werkzeug.cortexa7hf_neon 0WARNING: Value for scheme.14purelib does not match.1-r0Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3-werkzeug-tests.cortexa7hf_neon 0.14.19/site-r0 Complete!packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed bottle-0.12.19(desk-env) root@desk-mx6ul-axelulitelynx:~# dnf pip3 install python3requestsCollecting requests Downloading requests-ujsonLast metadata expiration check: 2.27.1:31:56 ago on Wed Oct 6 08:39:56 2021-py2.Dependencies resolvedpy3-none-any.whl (63 kB) |████████████████████████████████| 63 kB 141 kB/sRequirement already satisfied: idna<4,>=2.5 in ./desk-env/lib/python3.9/site-packages (from requests) (3.3)Collecting charset-normalizer~=2.0.0 Downloading charset_normalizer-2.0.10-py3-none-any.whl (39 kB)Collecting certifi>=2017.4.17 Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB) |████████████████████████████████| 149 kB 2.2 MB/sCollecting urllib3<1.27,>=============================================================================1.21.1 Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB) |████████████████████████████████| 138 kB 2.2 MB/sInstalling collected packages: urllib3, charset-normalizer, certifi, requests WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages Package Arch Version Repository Size sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user =False home =None root =None prefix =NoneSuccessfully installed certifi-2021.10.8 charset-normalizer-2.0.10 requests-2.27.1 urllib3-1.26.8(desk-env) root@desk-mx6ul-lynx:~# pip3 install schemaCollecting schema Downloading schema-0.7.5-py2.py3-none-any.whl (17 kB)Collecting contextlib2>============================================================================0.5.5Installing: python3 Downloading contextlib2-21.6.0-ujson cortexa7hf_neon 1py2.35py3-r0 cortexa7hf 24 knone-any.whl (13 kB)Installing collected packages: contextlib2, schemaTransaction Summary============================================================================ WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user =False home =None root =None prefix =NoneInstall 1 PackageSuccessfully installed contextlib2-21.6.0 schema-0.7.5 Total download size(desk-env) root@desk-mx6ul-lynx: 24 k~# pip3 install ssdpInstalled size: 59 kIs this ok [y/N]: yCollecting ssdp Downloading Packages:python3ssdp-1.1.0-ujsonpy2.py3-1.35none-r0any.cortexa7hf_neonwhl (4.rpm 22 3 kB/s | 24 kB 00)Installing collected packages:01ssdp WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed ssdp-1.1.0(desk-env) root@desk-mx6ul-lynx:~# pip3 install scapyCollecting scapy Downloading scapy-2.4.5.tar.gz (1.1 MB) |████████████████████████████████| 1.1 MB 1.4 MB/s Preparing metadata (setup.py) ... doneBuilding wheels for collected packages: scapy Building wheel for scapy (setup.py) ... done Created wheel for scapy: filename=scapy-2.4.5-py2.py3-none------------------------------------------------------------------any.whl size=1261555 sha256=df65309a4f5e0ee8e9f5da16f5b22b41c5a3d0ab03d671f788451874deeca183Total 21 kB Stored in directory: /home/root/s | 24 kB 00:01Running transaction checkTransaction check succeeded.cache/pip/wheels/c8/9b/2f/012f0dbaf869afac8be52d4423f34eaa0b6c5c2d1292e40ebdRunning transaction testSuccessfully built scapyTransaction test succeeded.Running transaction Preparing Installing collected packages: 1/1scapy Installing WARNING: python3-ujson-1Value for scheme.35-r0platlib does not match. Please report this to <https://github.cortexa7hf_neon 1com/pypa/pip/issues/110151> Verifying distutils: /home/root/desk-env/lib/python3-ujson-1.359/site-r0.cortexa7hf_neon 1/1packages Installed sysconfig: /usr/lib/python3.9/site-ujsonpackages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.cortexa7hf_neon 1com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.359/site-r0packages sysconfig: /usr/lib/python3.9/site-packagesComplete! WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed scapy-2.4.5(desk-env) root@desk-mx6ul-lynx:~# pip3 install nmapCollecting nmap Downloading nmap-0.0.1-py3-none-any.whl (2.7 kB)Installing collected packages: nmap WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed nmap-0.0.1(desk-env) root@desk-mx6ul-lynx:~# pip3 install ujsonCollecting ujson Downloading ujson-5.1.0.tar.gz (7.1 MB) |████████████████████████████████| 7.1 MB 10 kB/s WARNING: Value for prefixed-purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /tmp/pip-build-env-y3_ib386/normal/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for prefixed-platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /tmp/pip-build-env-y3_ib386/normal/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = '/tmp/pip-build-env-y3_ib386/normal' WARNING: Value for prefixed-purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /tmp/pip-build-env-y3_ib386/overlay/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for prefixed-platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /tmp/pip-build-env-y3_ib386/overlay/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = '/tmp/pip-build-env-y3_ib386/overlay' WARNING: Value for purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = None WARNING: Value for platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... doneBuilding wheels for collected packages: ujson Building wheel for ujson (pyproject.toml) ... done Created wheel for ujson: filename=ujson-5.1.0-cp39-cp39-linux_armv7l.whl size=37764 sha256=adb6cfae7a4edcd38706c5b910adeee4549af56433bbe17eed89b08f77dd25aa Stored in directory: /home/root/.cache/pip/wheels/5b/11/cb/2e1acde83fd78adc6581984c55442e63d7595711b0b62d8110Successfully built ujsonInstalling collected packages: ujson WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed ujson-5.1.0(desk-env) root@desk-mx6ul-lynx:~#</pre>=== check for installed packages and version ===<pre class="board-terminal">(desk-env) root@desk-mx6ul-lynx:~# pip3 listPackage Version------------------ ---------anyio 3.5.0bottle 0.12.19certifi 2021.10.8charset-normalizer 2.0.10click 8.0.3contextlib2 21.6.0fastapi 0.72.0Flask 2.0.2idna 3.3itsdangerous 2.0.1Jinja2 3.0.3MarkupSafe 2.0.1nmap 0.0.1pip 21.3.1pydantic 1.9.0pymodbus 2.5.3pyserial 3.5requests 2.27.1scapy 2.4.5schema 0.7.5setuptools 60.5.0six 1.16.0sniffio 1.2.0ssdp 1.1.0starlette 0.17.1typing_extensions 4.0.1ujson 5.1.0urllib3 1.26.8Werkzeug 2.0.2wheel 0.37.1(desk-env) root@desk-mx6ul-axelulitelynx:~#
</pre>
As you can see, ''dnf'' automatically manage the dependencies: for example, ''flask '' procedure install also '''Jinja2'', ''Markupsafe'', ''simplejson'', ''Werkzeug''. === import packages===
Finally, after the installation steps, it is possible to ''import'' the packages:
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# python3Python 3.59.5 4 (default, Jul 16 2020Apr 4 2021, 1618:1123:1351)[GCC 710.32.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import os
>>> import time
>>> import supervisor
>>> import ssl
>>> import nmap
>>> import requests
>>> import flask
>>> import fastapi
>>> import bottle
>>> import ujson
>>> import paho>>>(desk-env) root@desk-mx6ul-lynx:~#
</pre>
8,204
edits