Open main menu

DAVE Developer's Wiki β

Changes

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

2,856 bytes added, 13:10, 13 October 2021
import packages
</pre>
=== import packages===
Finally, after the installation steps, it is possible to ''import'' the packages:
>>>
</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.
 
* create the the <code>virtual environment</code>
<pre class="board-terminal">
root@desk-mx6ul-axelulite:~# python3 -m venv desk-env
root@desk-mx6ul-axelulite:~# which pip3
/usr/bin/pip3
root@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/sbcrin-env/bin/pip3
(desk-env) root@desk-mx6ul-axelulite:~# pip3 list
DEPRECATION: 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.
</pre>
* update ''pip3'' in the the <code>virtual environment</code>
<pre class="board-terminal">
(sbcrin-env) root@desk-mx6ul-axelulite:~# python3 -m pip install --upgrade pip
Cache entry deserialization failed, entry ignored
Collecting 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/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Successfully installed pip-20.3.4
You 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 --version
pip 20.3.4 from /home/root/sbcrin-env/lib/python3.5/site-packages/pip (python 3.5)
(desk-env) root@desk-mx6ul-axelulite:~# pip3 list
DEPRECATION: 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.4
setuptools 28.8.0
(sbcrin-env) root@desk-mx6ul-axelulite:~#
</pre>
 
then it is possible to install the required packages (with their specific version required) only in this ''virtual environment''
8,204
edits