Open main menu

DAVE Developer's Wiki β

Changes

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

5,026 bytes added, 09:40, 21 January 2022
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 that sometimes need a specific version of a library. In this way it is possible to install the required packages (with their specific version required) only in this ''virtual environment'' (which may differ from the ''root'' installation).
* for example, create the <code>virtual environment</code> named '''desk'''
</pre>
In this way it is possible to install the required packages (with their specific version required) only in this ''virtual environment'' (which may differ from the ''root'' installation). After pip3 installation, the available (base) packages are* <code>setuptools</code> can be upgraded too:
<pre class="board-terminal">
(desk-env) root@desk-mx6ul-lynx:~# pip3 listPackage Version---------- ------install --upgrade setuptoolsRequirement already satisfied: setuptools in ./desk-env/lib/python3.9/site-packages (49.2.1)Collecting setuptools Using cached setuptools-60.5.0-py3-none-any.whl (958 kB)Installing collected packages: setuptools Attempting uninstall: setuptoolsbtrfsutil 5 Found existing installation: setuptools 49.102.1gpg Uninstalling setuptools-49.2.1: Successfully uninstalled setuptools-49.152.1-unknowniniparse 0WARNING: Value for scheme.platlib does not match. Please report this to <https://github.4com/pypa/pip/issues/10151>libcomps 0distutils: /home/root/desk-env/lib/python3.19/site-packages sysconfig: /usr/lib/python3.159/site-packagespip 21 WARNING: Value for scheme.purelib does not match.3Please report this to <https://github.1com/pypa/pip/issues/10151>PyGObject 3 distutils: /home/root/desk-env/lib/python3.389/site-packages sysconfig: /usr/lib/python3.09/site-packages WARNING: Additional context: user = False home = None root = None prefix = NoneSuccessfully installed setuptools -60.5.0six 1.15.0wheel 0.37.1(desk-env) root@desk-mx6ul-lynx:~#
</pre>
Collecting pyserial
Downloading pyserial-3.5-py2.py3-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
Installing collected packages: pyserial
WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
prefix = None
Successfully installed pyserial-3.5
(desk-env) root@desk-mx6ul-lynx:~# pip3 install modbuspymodbus
Collecting 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)
prefix = None
Successfully installed pymodbus-2.5.3 six-1.16.0
(desk-env) root@desk-mx6ul-lynx:~# pip3 install flask
Collecting flask
Downloading Flask-2.0.2-py3-none-any.whl (95 kB)
|████████████████████████████████| 95 kB 422 kB/s
Collecting Werkzeug>=2.0
Downloading Werkzeug-2.0.2-py3-none-any.whl (288 kB)
|████████████████████████████████| 288 kB 2.1 MB/s
Collecting itsdangerous>=2.0
Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting click>=7.1.2
Downloading click-8.0.3-py3-none-any.whl (97 kB)
|████████████████████████████████| 97 kB 226 kB/s
Collecting Jinja2>=3.0
Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
|████████████████████████████████| 133 kB 2.1 MB/s
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.0.1.tar.gz (18 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: MarkupSafe
Building wheel for MarkupSafe (setup.py) ... done
Created wheel for MarkupSafe: filename=MarkupSafe-2.0.1-cp39-cp39-linux_armv7l.whl size=25720 sha256=4fa273af41ed51d0614beb76603162148fd15472aa0eb8c1c28a9c18ed137031
Stored in directory: /home/root/.cache/pip/wheels/9f/6d/c8/1f59b07cf85ae842908006ec28f4477f7e4578df72c3eb0e46
Successfully built MarkupSafe
Installing collected packages: MarkupSafe, 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 = None
Successfully 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 fastapi
Collecting fastapi
Downloading fastapi-0.72.0-py3-none-any.whl (52 kB)
|################################████████████████████████████████| 52 kB 68 77 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.1 MB/s
Collecting starlette==0.17.1
Downloading starlette-0.17.1-py3-none-any.whl (58 kB)
|###############################████████████████████████████████| 58 kB 594 619 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.0-py3-none-any.whl (79 kB)
|###############################████████████████████████████████| 79 kB 729 797 kB/s
Collecting typing-extensions>=3.7.4.3
Downloading typing_extensions-4.0.1-py3-none-any.whl (22 kB)
Collecting idna>=2.8
Downloading idna-3.3-py3-none-any.whl (61 kB)
|###############################████████████████████████████████| 61 kB 805 770 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/issues/10151>
Collecting bottle
Downloading bottle-0.12.19-py3-none-any.whl (89 kB)
|################################████████████████████████████████| 89 kB 688 724 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>
Collecting requests
Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
|##############################████████████████████████████████| 63 kB 124 141 kB/s Requirement 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)
Requirement already satisfied: idna<4,Collecting certifi>=22017.4.17 Downloading certifi-2021.5 in 10./desk8-env/lib/python3py2.9/sitepy3-none-packages any.whl (from requests149 kB) (3 |████████████████████████████████| 149 kB 2.3)2 MB/s
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
|##############################████████████████████████████████| 138 kB 632 kB/s Collecting certifi>=20172.4.17 Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB) |###########################| 149 kB 547 kB2 MB/s
Installing 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>
Collecting scapy
Downloading scapy-2.4.5.tar.gz (1.1 MB)
|#########████████████████████████████████| 1.1 MB 1.3 4 MB/s Preparing metadata (setup.py) ... - \ doneUsing legacy 'Building wheels for collected packages: scapy Building wheel for scapy (setup.py install' ) ... done Created wheel for scapy, since package 'wheel' is not installed: filename=scapy-2.4.5-py2.py3-none-any.whl size=1261555 sha256=df65309a4f5e0ee8e9f5da16f5b22b41c5a3d0ab03d671f788451874deeca183 Stored in directory: /home/root/.cache/pip/wheels/c8/9b/2f/012f0dbaf869afac8be52d4423f34eaa0b6c5c2d1292e40ebdSuccessfully built scapy
Installing collected packages: scapy
WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
root = None
prefix = None
Running setup.py install for scapy ... / - \ | / done
Successfully installed scapy-2.4.5
(desk-env) root@desk-mx6ul-lynx:~# pip3 install nmap
Collecting 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-aajn4vfiy3_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-aajn4vfiy3_ib386/normal/lib/python3.9/site-packages
sysconfig: /usr/lib/python3.9/site-packages
WARNING: Additional context:
home = None
root = None
prefix = '/tmp/pip-build-env-aajn4vfiy3_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-aajn4vfiy3_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-aajn4vfiy3_ib386/overlay/lib/python3.9/site-packages
sysconfig: /usr/lib/python3.9/site-packages
WARNING: Additional context:
home = None
root = None
prefix = '/tmp/pip-build-env-aajn4vfiy3_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
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) ... - \ done
Building 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=10ac0ac0859d098528a5985fb09ddc0dcb2e7682ff9d587cbae8be01dafe3eddadb6cfae7a4edcd38706c5b910adeee4549af56433bbe17eed89b08f77dd25aa
Stored in directory: /home/root/.cache/pip/wheels/5b/11/cb/2e1acde83fd78adc6581984c55442e63d7595711b0b62d8110
Successfully built ujson
prefix = None
Successfully installed ujson-5.1.0
(desk-env) root@desk-mx6ul-lynx:~#
</pre>
=== check for installed packages and version ===
scapy 2.4.5
schema 0.7.5
setuptools 4960.25.10
six 1.16.0
sniffio 1.2.0
>>> import requests
>>> import flask
>>> import fastapi
>>> import bottle
>>> import ujson
>>> import fastapi
>>>
(desk-env) root@desk-mx6ul-lynx:~#
</pre>
8,220
edits