Changes

Jump to: navigation, search

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

9,016 bytes removed, 16:22, 19 January 2022
no edit summary
{{InfoBoxTop}}
{{AppliesToAXEL ULite AN}}
{{AppliesTo_SBC_Lynx_AN}}
{{InfoBoxBottom}}
!Development Kit version
|-
| {{oldid|14782| 1.0.0}}
| Oct 2021
|{{oldid|14780|DESK-MX6UL-L 1.0.1}}|-| 2.0.0| --- 2022|[[DESK-MX6UL-L/General/Release_Notes#DESK-MX6UL-L_1L_3.0.10|DESK-MX6UL-L 13.0.10]]
|-
|}
== Python on DESK ==
<code>python</code> (i.e. '''python2''') and <code>python3</code> applications are application 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.
== Installing python packages ==
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# python3 --versionPython 3.5.5root@desk-mx6ul-axelulite:~# pippip pip2 pip2.7root@desk-mx6ul-axelulite:~# pip --versionpip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)4root@desk-mx6ul-axelulitelynx:~#
</pre>
This shows that <code>pip3</code> is not present in the - ''by default'' - on standard root file system and should , but can be easily installed: the simpler way is using python3 itself and the provided python script [https://bootstrap.pypa.io/pip/3.5/get-pip.py get-pip.py] for version 3.5:
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# python3 curl https://bootstrap.pypa.io/get-pip.pyDEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. -o get-pip 21.py % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 will drop support for Python 3.5 in January 2021. :00:01 --:--:-- 1846kroot@desk-mx6ul-lynx:~# python3 get-pip 21.0 will remove support for this functionality.py Collecting pip<21.0 Downloading pip-2021.3.41-py2.py3-none-any.whl (1.5 7 MB) |#####################| 1.7 MB 2.1 MB/s Collecting setuptools Downloading setuptools-60.5.0-py3-none-any.whl (958 kB) |###########| 958 kB 2.1.5 MB 176 kB/s
Collecting wheel
Downloading wheel-0.37.01-py2.py3-none-any.whl (35 kB)Installing collected packages: wheel, setuptools, pipSuccessfully installed pip-2021.3.4 1 setuptools-60.5.0 wheel-0.37.01WARNING: Running pip as the 'root@desk-mx6ul-axelulite' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https:~# //pippip pip2 pip2.7 pip3 pip3pypa.5io/warnings/venvroot@desk-mx6ul-axelulitelynx:~#
</pre>
After the installation, <code>pip3</code> is the latest version available for '''Python3 3.59.54''':
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# pip3 --versionpip 2021.3.4 1 from /usr/lib/python3.59/site-packages/pip (python 3.59)root@desk-mx6ul-axelulite:~# easy3_install --versionsetuptools 39.0.0 from /usr/lib/python3.5/site-packages (Python 3.5)root@desk-mx6ul-axelulitelynx:~#
</pre>
=== easy install=Virtual environments ==Even if <code>easy_install</code> tool As explained on [https://setuptoolsdocs.pypapython.io/enorg/latest3/deprecatedtutorial/easy_installvenv.html has been deprecatedpython3 12. Virtual Environments and Packages], tutorial it is better to ''"create a useful tool still present in the typical python distributions.virtual environment, a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages"''
For This avoids the purposes of this Application Note, the tool has been used problem related to install some python packages typically used in an Industrial Gateway equipment In this example, the following packages are installed using <code>easy3_install</code> (''easy_install'' Applications that sometimes need a specific version for python3): '''pyserial''' and '''pymodbus''' (for bus communications), '''[https://docsof a library.python-requests.org/en/latest/ requests]''' (HTTP library), '''schema''', '''ssdp''':
* for example, create the <code>virtual environment</code> named '''desk'''
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# easy3_install pyserialSearching for pyserialReading https://pypi.python.org/simple/pyserial/Downloading https://files.pythonhosted.org/packages/07/bc/587a445451b253b285629263eb51c2d8e9bcea4fc97826266d186f96f558/pyserial-3.5-py2.py3-none-any.whl#sha256=c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0Best match: pyserial 3.5Processing pyserial-3.5-py2.py3-none-any.whlInstalling pyserial-3.5-py2.py3-none-any.whl to /usr/lib/python3.5/site-packageswriting requirements to /usr/lib/python3.5/site-packages/pyserial-3.5-py3.5.egg/EGG-INFO/requires.txtAdding pyserial 3.5 to easy-install.pth fileInstalling pyserial-miniterm script to /usr/binInstalling pyserial-ports script to /usr/bin Installed /usr/lib/python3.5/site-packages/pyserial-3.5-py3.5.eggProcessing dependencies for pyserialFinished processing dependencies for pyserialroot@m venv desk-mx6ul-axelulite:~# easy3_install pymodbusSearching for pymodbusReading https://pypi.python.org/simple/pymodbus/Downloading https://files.pythonhosted.org/packages/57/21/6c9b1cade55161444450bdde6e953edb819d984beafee8d4baefa4f0310c/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-py2.py3-none-any.whl to /usr/lib/python3.5/site-packageswriting requirements to /usr/lib/python3.5/site-packages/pymodbus-2.5.3rc1-py3.5.egg/EGG-INFO/requires.txtAdding pymodbus 2.5.3rc1 to easy-install.pth fileInstalling pymodbus.console script to /usr/binInstalling pymodbus.server 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 to /usr/lib/python3.5/site-packagesAdding six 1.16.0 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/six-1.16.0-py3.5.eggFinished processing dependencies for pymodbusenvroot@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/EGG-INFO/requires.txtAdding requests 2.26.0 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/requests-2.26.0-py3.5.eggProcessing dependencies for requestsSearching for urllib3<1.27,>=1.21.1Reading https://pypi.python.org/simple/urllib3/Downloading https://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 filewhich pip3 Installed /usr/lib/python3.5/site-packages/urllib3-1.26.7-py3.5.eggSearching for idna<4,>=2.5Reading https://pypi.python.org/simple/idna/Downloading https://files.pythonhosted.org/packages/d7/77/ff688d1504cdc4db2a938e2b7b9adee5dd52e34efbd2431051efc9984de9/idna-3.2-py3-none-any.whl#sha256=14475042e284991034cb48e06f6851428fb14c4dc953acd9be9a5e95c7b6dd7aBest match: idna 3.2Processing idna-3.2-py3-none-any.whlInstalling idna-3.2-py3-none-any.whl to /usr/lib/python3.5/site-packagesAdding idna 3.2 to easy-install.pth file Installed /usr/lib/python3.5/site-packages/idna-3.2-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-packageswriting 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 requestsroot@desk-mx6ul-axelulite:~# easy3_install schemaSearching for schemaReading https://pypi.python.org/simple/schema/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 /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 contextlib2>=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=3fbdb64466afd23abaf6c977627b75b6139a5a3e8ce38405c5b413aed7a0471fBest match: contextlib2 21.6.0Processing contextlib2-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 schemaroot@desk-mx6ul-axelulite:~# 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-none-any.whl to /usr/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 ssdppip3root@desk-mx6ul-axelulitelynx:~#
</pre>
 Then, add some useful IP packages like '''nmap''' or '''[https:* activate the <code>virtual environment<//scapy.readthedocs.io/en/latest/ scapy]''' (network packet manipulation):code>
<pre class="board-terminal">
root@desk-mx6ul-axelulitelynx:~# easy3_install nmapSearching for nmapReading https://pypi.python.org/simple/nmap/Downloading https://files.pythonhosted.org/packages/f8/6f/6813025bd575ebc771189afaab7c405fdf3f1febaa197525d5aa6fd88ac5/nmapsource desk-0.0.1-py3-none-any.whl#sha256=158de16af02043e1a2015662ad1710dfb46dadd2bea8e9d90ba16b78b6650098Best match: nmap 0.0.1Processing nmap-0.0.1-py3-none-any.whlInstalling nmap-0.0.1-py3-none-any.whl to env/usr/lib/python3.5bin/site-packagesactivateAdding nmap 0.0.1 to easy(desk-install.pth file Installed /usr/lib/python3.5/site-packages/nmap-0.0.1-py3.5.eggProcessing dependencies for nmapFinished processing dependencies for nmapenv) root@desk-mx6ul-axelulitelynx:~# easy3_install scapySearching for scapywhich pip3Reading https:/home/pypi.python.orgroot/simple/scapy/Downloading https://files.pythonhosted.org/packages/85/47/c919432ca258f354bb2c1e645623f891603f185bfc7563d4a21f6432e7ed/scapy-2.4.5.tar.gz#sha256=bc707e3604784496b6665a9e5b2a69c36cc9fb032af4864b29051531b24c8593Best match: scapy 2.4.5Processing scapydesk-2.4.5.tar.gzWriting env/tmp/easy_install-vsqq0ans/scapy-2.4.5bin/setup.cfgpip3Running scapy(desk-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vsqq0ans/scapy-2.4.5/egg-dist-tmp-nauxdhas/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type' warnings.warn(msgenv)creating /usr/lib/python3.5/site-packages/scapy-2.4.5-py3.5.eggExtracting scapy-2.4.5-py3.5.egg to /usr/lib/python3.5/site-packagesAdding scapy 2.4.5 to easy-install.pth fileInstalling scapy script to /usr/binInstalling UTscapy script to /usr/bin Installed /usr/lib/python3.5/site-packages/scapy-2.4.5-py3.5.eggProcessing dependencies for scapyFinished processing dependencies for scapyroot@desk-mx6ul-axelulitelynx:~#
</pre>
 and finally an MQTT client like [http:* update ''pip3'' in the the <code>virtual environment<//www.eclipse.org/paho/ Eclipse paho MQTT] is installed too:code>
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# easy3_install paho-mqttSearching for paho-mqttReading https:/home/root/pypi.python.orgdesk-env/simplebin/pahopython3 -m pip install -mqtt/-upgrade pipCollecting pipDownloading https://files Using cached pip-21.pythonhosted3.org/packages/32/d3/6dcb8fd14746fcde6a556f932b5de8bea8fedcb85b3a092e0e986372c0e7/paho1-py3-mqttnone-1.5any.whl (1.tar.gz#sha256=9feb068e822be7b3a116324e01fb6028eb1d66412bf98595ae72698965cb1cae7 MB)Installing collected packages: pip Attempting uninstall: pipBest match Found existing installation: paho-mqtt 1pip 20.52.13Processing paho-mqtt Uninstalling pip-120.52.1.tar.gz3:Writing /tmp/easy_install-vkarrpqi/paho-mqtt Successfully uninstalled pip-1.520.1/setup2.cfg3Running paho-mqttSuccessfully installed pip-121.53.1/setup.py (desk-q bdist_egg env) root@desk-mx6ul-dist-dir lynx:~# /home/tmproot/easy_installdesk-vkarrpqienv/bin/pahopip3 -mqtt-1versionpip 21.53.1from /home/egg-dist-tmproot/desk-tt8lku70creating /usrenv/lib/python3.59/site-packages/paho_mqtt-1.5.1-py3.5pip (python 3.egg9)Extracting paho_mqtt(desk-1.5.1env) root@desk-py3.5.egg to /usr/lib/python3.5/sitemx6ul-packageslynx:~# Adding paho-mqtt 1.5.1 to easy-install.pth file</pre>
Installed /usr/lib/python3.5/site-In this way it is possible to install the required packages/paho_mqtt-1.5.1-py3(with their specific version required) only in this ''virtual environment'' (which may differ from the ''root'' installation).5.eggProcessing dependencies for paho-mqttFinished processing dependencies for paho-mqttroot@desk-mx6ul-axelulite:~#</pre>
=== pip package installation===For the purposes of this Application Note, <code>pip3</code> has been used to install some python packages typically used in an Industrial Gateway equipment
On top of thatIn this example, some web the following packages are very useful installed '''pyserial''' and '''pymodbus''' (for creating bus communications), '''[https://flask.palletsprojects.com/en/2.0.x/ flask]''', '''[https://fastapi.tiangolo.com/ fastapi]''' (web applications and remotely control/get information from the gateway like framework), '''[https://bottlepy.org/docs/dev/ bottle]''' (lightweight WSGI micro web-framework), '''[https://docs.python-requests.org/en/latest/ requests]''' (HTTP library), '''schema''', '''ssdp''', '''[https://scapy.readthedocs.io/en/latest/ scapy]''' (network packet manipulation), '''nmap''', '''[https://pypi.org/project/ujson/ ujson]''' (JSON framework):
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-lynx:~# pip3 install pyserialCollecting pyserial Downloading pyserial-3.5-py2.py3-none-any.whl (90 kB) |################################| 90 kB 780 kB/s Installing 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.5(desk-env) root@desk-mx6ul-axelulitelynx:~# pip3 install bottlemodbusCollecting pymodbus Downloading pymodbus-2.5.3-py2.py3-none-any.whl (154 kB) |#############################| 154 kB 1.5 MB/s Collecting six>=1.15.0 Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)DEPRECATIONRequirement already satisfied: Python pyserial>=3.4 in ./desk-env/lib/python3.9/site-packages (from pymodbus) (3.5 reached the end of its life on September 13th)Installing collected packages: six, 2020pymodbus WARNING: Value for scheme.platlib does not match. Please upgrade your Python as Python 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 pymodbus-2.5.3 six-1.16.0(desk-env) root@desk-mx6ul-lynx:~# pip3 install fastapiCollecting fastapi Downloading fastapi-0.72.0-py3-none-any.whl (52 kB) |################################| 52 kB 68 kB/s Collecting starlette==0.17.1 Downloading starlette-0.17.1-py3-none-any.whl (58 kB) |###############################| 58 kB 594 kB/s Collecting 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.3 MB/s Collecting anyio<4,>=3.0.0 Downloading anyio-3.5 is no longer maintained. 0-py3-none-any.whl (79 kB) |###############################| 79 kB 729 kB/s Collecting 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) |###############################| 61 kB 805 kB/s Installing collected packages: sniffio, idna, typing-extensions, anyio, starlette, pydantic, fastapi WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip 21/issues/10151> distutils: /home/root/desk-env/lib/python3.0 will drop support 9/site-packages sysconfig: /usr/lib/python3.9/site-packages WARNING: Value for Python 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 anyio-3.5 in January 2021. pip 210 fastapi-0.72.0 idna-3.3 pydantic-1.9.0 sniffio-1.2.0 starlette-0.17.1 typing-extensions-4.0 will remove support for this functionality.1(desk-env) root@desk-mx6ul-lynx:~# pip3 install bottle
Collecting bottle
Downloading bottle-0.12.19-py3-none-any.whl (89 kB)
|################################| 89 kB 486 688 kB/s
Installing collected packages: bottle
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 = None
Successfully installed bottle-0.12.19
(desk-env) root@desk-mx6ul-axelulitelynx:~#pip3 install requestsCollecting requests Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB) |##############################| 63 kB 124 kB/s Collecting charset-normalizer~=2.0.0 Downloading charset_normalizer-2.0.10-py3-none-any.whl (39 kB)Requirement already satisfied: idna<4,>=2.5 in ./desk-env/lib/python3.9/site-packages (from requests) (3.3)Collecting urllib3<1.27,>=1.21.1 Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB) |##############################| 138 kB 632 kB/pres Collecting certifi>=2017.4.17 Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)and JSON framework like '''[ |###########################| 149 kB 547 kB/s Installing collected packages: urllib3, charset-normalizer, certifi, requests WARNING: Value for scheme.platlib does not match. Please report this to <https://pypigithub.orgcom/projectpypa/ujsonpip/issues/ ujson]'''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 <pre classhttps://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 ="boardNone root = None prefix = NoneSuccessfully installed certifi-2021.10.8 charset-normalizer-2.0.10 requests-2.27.1 urllib3-terminal">1.26.8(desk-env) root@desk-mx6ul-axelulitelynx:~# pip3 install ujsonschemaCollecting schema Downloading schema-0.7.5-py2.py3-none-any.whl (17 kB)DEPRECATION: Python 3Collecting contextlib2>=0.5.5 reached the end of its life on September 13th Downloading contextlib2-21.6.0-py2.py3-none-any.whl (13 kB)Installing collected packages: contextlib2, 2020schema 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 upgrade your Python as Python 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 contextlib2-21.6.0 schema-0.7.5(desk-env) root@desk-mx6ul-lynx:~# pip3 install ssdpCollecting ssdp Downloading ssdp-1.1.0-py2.py3-none-any.whl (4.3kB)Installing collected packages: ssdp 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.3 MB/s Preparing metadata (setup.py) ... - \ doneUsing legacy 'setup.py install' for scapy, since package 'wheel' is no longer maintainednot installed.Installing collected packages: scapy WARNING: Value for scheme.platlib does not match. Please report this to <https://github. com/pypa/pip 21/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 = None Running setup.py install for scapy ... / - \ | / doneSuccessfully installed scapy-2.4.5(desk-env) root@desk-mx6ul-lynx:~# pip3 install nmapCollecting nmap Downloading nmap-0.0 will drop support .1-py3-none-any.whl (2.7 kB)Installing collected packages: nmap WARNING: Value for Python 3scheme.platlib does not match.5 in January 2021Please report this to <https://github. com/pypa/pip 21/issues/10151> distutils: /home/root/desk-env/lib/python3.9/site-packages sysconfig: /usr/lib/python3.0 will remove support 9/site-packages WARNING: Value for scheme.purelib does not match. Please report this functionalityto <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 ujson
Collecting ujson
Downloading ujson-35.21.0.tar.gz (7.1 MB) |################################| 7.1 MB 21 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-aajn4vfi/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-aajn4vfi/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-aajn4vfi/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-aajn4vfi/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-aajn4vfi/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-aajn4vfi/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 wheel metadata (pyproject.toml) .. . - \ done
Building wheels for collected packages: ujson
Building wheel for ujson (PEP 517pyproject.toml) ... - \ | / - \ | done Created wheel for ujson: filename=ujson-35.21.0-cp35cp39-cp35mcp39-linux_armv7l.whl size=168783 37764 sha256=69ee66de3fdd504505c0b3bd0e6e9b54cc322a93374c50eec92b18077523b3d310ac0ac0859d098528a5985fb09ddc0dcb2e7682ff9d587cbae8be01dafe3edd Stored in directory: /home/root/.cache/pip/wheels/d75b/f511/aecb/ca9a177378cfd568da6585bf3f10a79d3d577332ef1e3278db2e1acde83fd78adc6581984c55442e63d7595711b0b62d8110
Successfully built ujson
Installing 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-35.21.0(desk-env) root@desk-mx6ul-axelulitelynx:~#
</pre>
 ==== check for installed packages and version ====
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-axelulitelynx:~# pip3 listDEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Package Version
------------------ ---------
anyio 3.5.0
bottle 0.12.19
certifi 2021.510.308charset-normalizer 2.0.610click 68.70.3
contextlib2 21.6.0
dataclasses 0.8fastapi 0.6872.20Flask 2.0.12.2gpg 1.10.0idna 3.2iniparse 0.43itsdangerous 2.0.241Jinja2 23.0.103MarkupSafe 12.0.1
nmap 0.0.1
paho-mqtt 1.5.1pip 2021.3.41pydantic 1.89.2pygobject 3.28.10pymodbus 2.5.3rc13
pyserial 3.5
requests 2.2627.01
scapy 2.4.5
schema 0.7.45setuptools 3949.02.01simplejson 3six 1.1316.20six sniffio 1.112.0
ssdp 1.1.0
starlette 0.1417.21typing-extensions typing_extensions 3.104.0.21ujson 35.21.0urllib3 1.26.78Werkzeug 2.0.14.12wheel 0.37.0root@desk-mx6ul-axelulite:~#</pre> === DNF === 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]. In case of some troubles (which can happens using <code>easy_install</code> or <code>pip</code>), in fact, other packages can be directly installed using <code>dnf</code> from the already built ''rpm'' packages built with Yocto. For example, when ''non-pure'' python packages or in case of mismatched versions, it is required to install them from the pre-built images in Yocto, for example '''[https://flask.palletsprojects.com/en/2.0.x/ flask]''':: <pre class="board-terminal">root@desk-mx6ul-axelulite:~# dnf install python3-flaskLast metadata expiration check: 1:46:26 ago on Thu Oct 7 10:35:14 2021.Dependencies resolved.================================================================================ Package Arch Version Repository Size================================================================================Installing: python3-flask cortexa7hf_neon 0.12.2-r0 cortexa7hf 110 kInstalling dependencies: python3-click cortexa7hf_neon 6.7-r0 cortexa7hf 110 k python3-itsdangerous cortexa7hf_neon 0.24-r0 cortexa7hf 23 k python3-jinja2 cortexa7hf_neon 2.10-r0 cortexa7hf 187 k python3-markupsafe cortexa7hf_neon 1.0-r0 cortexa7hf 25 k python3-simplejson cortexa7hf_neon 3.13.2-r0 cortexa7hf 50 k python3-werkzeug cortexa7hf_neon 0.14.1-r0 cortexa7hf 375 k python3-werkzeug-tests cortexa7hf_neon 0.14.1-r0 cortexa7hf 32 k Transaction Summary================================================================================Install 8 Packages Total download size: 912 kInstalled size: 3.7 MIs this ok [y/N]: yDownloading Packages:(1/8): python3-itsdangerous-0.24-r0.cortexa7hf_ 205 kB/s | 23 kB 00:00(2/8): python3-flask-0.12.2-r0.cortexa7hf_neon. 358 kB/s | 110 kB 00:00(3/8): python3-jinja2-2.10-r0.cortexa7hf_neon.r 550 kB/s | 187 kB 00:00(4/8): python3-click-6.7-r0.cortexa7hf_neon.rpm 227 kB/s | 110 kB 00:00(5/8): python3-werkzeug-tests-0.14.1-r0.cortexa 445 kB/s | 32 kB 00:00(6/8): python3-simplejson-3.13.2-r0.cortexa7hf_ 643 kB/s | 50 kB 00:00(7/8): python3-markupsafe-1.0-r0.cortexa7hf_neo 365 kB/s | 25 kB 00:00(8/8env): python3-werkzeug-0.14.1-r0.cortexa7hf_ne 603 kB/s | 375 kB 00:00--------------------------------------------------------------------------------Total 934 kB/s | 912 kB 00:00Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction Preparing : 1/1 Installing : python3-werkzeug-0.14.1-r0.cortexa7hf_neon 1/8 Installing : python3-werkzeug-tests-0.14.1-r0.cortexa7hf_neon 2/8 Installing : python3-markupsafe-1.0-r0.cortexa7hf_neon 3/8 Installing : python3-jinja2-2.10-r0.cortexa7hf_neon 4/8 Installing : python3-simplejson-3.13.2-r0.cortexa7hf_neon 5/8 Installing : python3-itsdangerous-0.24-r0.cortexa7hf_neon 6/8 Installing : python3-click-6.7-r0.cortexa7hf_neon 7/8 Installing : python3-flask-0.12.2-r0.cortexa7hf_neon 8/8 Verifying : python3-flask-0.12.2-r0.cortexa7hf_neon 1/8 Verifying : python3-click-6.7-r0.cortexa7hf_neon 2/8 Verifying : python3-itsdangerous-0.24-r0.cortexa7hf_neon 3/8 Verifying : python3-jinja2-2.10-r0.cortexa7hf_neon 4/8 Verifying : python3-werkzeug-0.14.1-r0.cortexa7hf_neon 5/8 Verifying : python3-werkzeug-tests-0.14.1-r0.cortexa7hf_neon 6/8 Verifying : python3-simplejson-3.13.2-r0.cortexa7hf_neon 7/8 Verifying : python3-markupsafe-1.0-r0.cortexa7hf_neon 8/8 Installed: python3-flask.cortexa7hf_neon 0.12.2-r0 python3-click.cortexa7hf_neon 6.7-r0 python3-itsdangerous.cortexa7hf_neon 0.24-r0 python3-jinja2.cortexa7hf_neon 2.10-r0 python3-markupsafe.cortexa7hf_neon 1.0-r0 python3-simplejson.cortexa7hf_neon 3.13.2-r0 python3-werkzeug.cortexa7hf_neon 0.14.1-r0 python3-werkzeug-tests.cortexa7hf_neon 0.14.1-r0 Complete!root@desk-mx6ul-axelulitelynx:~#
</pre>
<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 bottle
>>> import ujson
>>> import pahofastapi>>></pre> == Virtual environments ==As explained on [https://docs.python.org/3/tutorial/venv.html python3 12. Virtual Environments and Packages] tutorial it is better to ''"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"'' This avoids the problem related to Applications which sometimes need a specific version of a library. * for example, create the <code>virtual environment</code> named '''desk'''<pre class="board-terminal">root@desk-mx6ul-axelulite:~# python3 -m venv desk-envroot@desk-mx6ul-axelulite:~# which pip3/usr/bin/pip3root@desk-mx6ul-axelulite:~# </pre> * activate the <code>virtual environment</code><pre class="board-terminal">root@desk-mx6ul-axelulite:~# source desk-env/bin/activate(desk-env) root@desk-mx6ul-axelulite:~# which pip3/home/root/desk-env/bin/pip3(desk-env) root@desk-mx6ul-axelulite:~# pip3 listDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.pip (9.0.1)setuptools (28.8.0)You are using pip version 9.0.1, however version 21.3 is available.You should consider upgrading via the 'pip install --upgrade pip' command.root@desk-mx6ul-axelulite:~# </pre>* update ''pip3'' in the the <code>virtual environment</code><pre class="board-terminal">(desk-env) root@desk-mx6ul-axelulite:~# python3 -m pip install --upgrade pipCache entry deserialization failed, entry ignoredCollecting pip Cache entry deserialization failed, entry ignored Downloading https://files.pythonhosted.org/packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-20.3.4-py2.py3-none-any.whl (1.5MB) 100% |################################| 1.5MB 56kB/sInstalling collected packages: pip Found existing installation: pip 9.0.1 Uninstalling pip-9.0.1: Successfully uninstalled pip-9.0.1Successfully installed pip-20.3.4You are using pip version 20.3.4, however version 21.3 is available.You should consider upgrading via the 'pip install --upgrade pip' command.(desk-env) root@desk-mx6ul-axelulite:~# pip3 --versionpip 20.3.4 from /home/root/desk-env/lib/python3.5/site-packages/pip (python 3.5)(desk-env) root@desk-mx6ul-axelulite:~# pip3 listDEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.Package Version---------- -------pip 20.3.4setuptools 28.8.0(desk-env) root@desk-mx6ul-axelulite:~#</pre> in this way it is possible to install the required packages (with their specific version required) only in this ''virtual environment'' (which is different from the ''root'' installation): <pre class="board-terminal">(desk-env) root@desk-mx6ul-axelulite:~# pip3 install requests==2.25.0DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.Collecting requests==2.25.0 Downloading requests-2.25.0-py2.py3-none-any.whl (61 kB) |################################| 61 kB 467 kB/sCollecting idna<3,>=2.5 Downloading idna-2.10-py2.py3-none-any.whl (58 kB) |################################| 58 kB 598 kB/sCollecting chardet<4,>=3.0.2 Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB) |################################| 133 kB 2.1 MB/sCollecting certifi>=2017.4.17 Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB) |################################| 149 kB 2.1 MB/sCollecting urllib3<1.27,>=1.21.1 Downloading urllib3-1.26.7-py2.py3-none-any.whl (138 kB) |################################| 138 kB 2.1 MB/sInstalling collected packages: urllib3, idna, chardet, certifi, requestsSuccessfully installed certifi-2021.10.8 chardet-3.0.4 idna-2.10 requests-2.25.0 urllib3-1.26.7(desk-env) root@desk-mx6ul-axelulite:~# pip3 listDEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.Package Version---------- ---------certifi 2021.10.8chardet 3.0.4idna 2.10pip 20.3.4requests 2.25.0setuptools 28.8.0urllib3 1.26.7(desk-env) root@desk-mx6ul-axelulite:~# deactivateroot@desk-mx6ul-axelulite:~# pip3 list | grep requestsDEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.requests 2.26.0root@desk-mx6ul-axelulitelynx:~#
</pre>
8,226
edits

Navigation menu