Python Development and Debugging on TorizonCore Using Visual Studio Code
This article explains how to run and debug Python Applications on TorizonCore using the Visual Studio Code extension provided by Toradex.
This article complies to the Typographic Conventions for Torizon Documentation.
- Configure the Build Environment for Torizon Containers
- Python 3 installed on your OS. Python 2 is not supported.
- Read the article Visual Studio Code Extension for Torizon.
- Pay special attention to the commands tab.
- Have one of the OS below:
- Windows 10 Pro / Enterprise / Education
- Linux (it was validated using Ubuntu 18.04)
- Toradex Hardware with TorizonCore installed.
- Python Official extension for Visual Studio Code.
Create a New Project
F1 on Visual Studio Code and then type
Torizon/Python: Create Python Application to create an application:
You will be able to select a template. Some examples are a console or a Qt QML application.
After creating it, write the application name on the same command bar:
Now you should be able to select an application template, this will pre-create all the files required for a specific kind of application.
A bunch of options will appear, make sure to select the right target architecture:
For new projects we suggest choosing platforms based on debian bullseye, those are the platforms that will be maintained in the long term. Notice also that the list of platforms and templates may change after an update of the extension, providing new platforms for more recent versions of debian or templates for specific kinds of applications.
torizon on the username label:
A python project with the following files will be created, to learn more about each one of them refer to the Python Project Configuration Files section.
Pylint warning is not specific for Torizon, it will happen for any
.py file. Although not mandatory, a linter is really helpful and recommended during development.
Set the Default Python Interpreter
Some operating systems still point the
python executable to Python 2, others may only use the
python3 executable. You must make sure that Visual Studio Code is using a version of Python 3 as the default interpreter, otherwise, you may see an error message Path to shell executable "python" does not exist.
F1 and run the command
Python: Select Interpreter:
Select any version of Python 3:
Understand how to add Python packages and more in the next subsections.
Add Python Packages Available on Debian Feeds
Open the Torizon configuration page and edit the
extrapackages configuration, you just need to click on the pen icon:
As an example, add the package python3-pexpect:
This would be the equivalent of running
apt install python3-pexpect on the command-line. It does not use pip.
Python Project Configuration Files
The Torizon Extension for Visual Studio Code provides the following files for project configuration:
|File||Description||Example Use Case|
|setup.sh||Install additional components.||Run |
|requirements.txt||Python packages to be installed via pip, one per line with optional version||Please consider Add Python Packages Available on Debian Feeds as explained in the previous section.|
This will simplify the management of binary components and ensure that the package version works with all the other libs provided in Debian.
Use pip only for packages that are pure Python code and are not available on Debian. For instance,
|cleanup.sh||runs after pip has installed packages in requirements.txt.||Uninstall |
|.rsync-exclude-list||list of the folders that will not be copied to the target and added to the application container.||If you store files that are not meant to be shipped to the target in your app folder, add them to the list to save time and storage on deployment.|
Deploy and Debug
After configuring your project, you can now deploy and debug it. Since this is common to all languages supported by the extension, please refer to the section Deploy and Debug from the article Visual Studio Code Extension for Torizon.
Deploy and Release
After going through the process of deploying and debugging the application, you can now deploy and release it. Since this is common to all languages supported by the extension, please refer to the section Deploy and Release from the article Visual Studio Code Extension for Torizon.